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,108 +0,0 @@
|
|
|
1
|
-
import { 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
|
-
* Folds an {@link Optional} into a plain value by applying one of two case
|
|
8
|
-
* handlers: `some` if the {@link Optional} contains a value, `none`
|
|
9
|
-
* otherwise. This is the function form of pattern matching on an
|
|
10
|
-
* {@link Optional}.
|
|
11
|
-
*
|
|
12
|
-
* Unlike {@link Optional.map}, the result is not wrapped in an
|
|
13
|
-
* {@link Optional} — both branches produce the final value directly.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* const doubledOrZero = Optional.match(Optional.some(21), {
|
|
19
|
-
* some: (value) => value * 2,
|
|
20
|
-
* none: () => 0,
|
|
21
|
-
* });
|
|
22
|
-
*
|
|
23
|
-
* assert.deepStrictEqual(doubledOrZero, 42);
|
|
24
|
-
*
|
|
25
|
-
* const matcher = Optional.match({
|
|
26
|
-
* some: (value: number) => `value: ${value}`,
|
|
27
|
-
* none: () => 'none',
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* assert.deepStrictEqual(matcher(Optional.some(3)), 'value: 3');
|
|
31
|
-
*
|
|
32
|
-
* assert.deepStrictEqual(matcher(Optional.none), 'none');
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @template O The input `UnknownOptional` type.
|
|
36
|
-
* @template S2 The type returned by the `some` case.
|
|
37
|
-
* @template N2 The type returned by the `none` case.
|
|
38
|
-
* @param optional The `Optional` to match on.
|
|
39
|
-
* @param cases An object with a `some` handler receiving the contained value
|
|
40
|
-
* and a `none` handler receiving nothing.
|
|
41
|
-
* @returns The value produced by whichever case handler was applied.
|
|
42
|
-
*/
|
|
43
|
-
export function match<O extends UnknownOptional, S2, N2>(
|
|
44
|
-
optional: O,
|
|
45
|
-
cases: Readonly<{
|
|
46
|
-
some: (value: Unwrap<O>) => S2;
|
|
47
|
-
none: () => N2;
|
|
48
|
-
}>,
|
|
49
|
-
): N2 | S2;
|
|
50
|
-
|
|
51
|
-
// Curried version
|
|
52
|
-
//
|
|
53
|
-
// The returned function is generic over the *whole* optional, mirroring the
|
|
54
|
-
// direct overload above; see the comment on the curried overload of
|
|
55
|
-
// `Optional.map` for why the parameter is a conditional type instead of a
|
|
56
|
-
// plain `Optional<S>`.
|
|
57
|
-
export function match<S, S2, N2>(
|
|
58
|
-
cases: Readonly<{
|
|
59
|
-
some: (value: S) => S2;
|
|
60
|
-
none: () => N2;
|
|
61
|
-
}>,
|
|
62
|
-
): <O extends UnknownOptional>(
|
|
63
|
-
optional: Unwrap<O> extends S ? O : never,
|
|
64
|
-
) => N2 | S2;
|
|
65
|
-
|
|
66
|
-
export function match<O extends UnknownOptional, S2, N2>(
|
|
67
|
-
...args:
|
|
68
|
-
| readonly [
|
|
69
|
-
optional: O,
|
|
70
|
-
cases: Readonly<{
|
|
71
|
-
some: (value: Unwrap<O>) => S2;
|
|
72
|
-
none: () => N2;
|
|
73
|
-
}>,
|
|
74
|
-
]
|
|
75
|
-
| readonly [
|
|
76
|
-
cases: Readonly<{
|
|
77
|
-
some: (value: Unwrap<O>) => S2;
|
|
78
|
-
none: () => N2;
|
|
79
|
-
}>,
|
|
80
|
-
]
|
|
81
|
-
): N2 | S2 | ((optional: O) => N2 | S2) {
|
|
82
|
-
switch (args.length) {
|
|
83
|
-
case 2: {
|
|
84
|
-
const [optional, cases] = args;
|
|
85
|
-
|
|
86
|
-
return matchImpl(optional, cases);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
case 1: {
|
|
90
|
-
// Curried version: the only argument is the case handlers
|
|
91
|
-
const [cases] = args;
|
|
92
|
-
|
|
93
|
-
return (optional: O) => matchImpl(optional, cases);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const matchImpl = <O extends UnknownOptional, S2, N2>(
|
|
99
|
-
optional: O,
|
|
100
|
-
cases: Readonly<{
|
|
101
|
-
some: (value: Unwrap<O>) => S2;
|
|
102
|
-
none: () => N2;
|
|
103
|
-
}>,
|
|
104
|
-
): N2 | S2 =>
|
|
105
|
-
isSome(optional)
|
|
106
|
-
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
107
|
-
cases.some(unwrap(optional)!)
|
|
108
|
-
: cases.none();
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type None } from '../../../types.mjs';
|
|
2
|
-
import { NoneTypeTagName } from './tag.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The singleton instance representing {@link None} (an empty
|
|
6
|
-
* Optional).
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const someValue = Optional.some({ id: 1 });
|
|
12
|
-
*
|
|
13
|
-
* const noneValue = Optional.none;
|
|
14
|
-
*
|
|
15
|
-
* assert.isTrue(Optional.isSome(someValue));
|
|
16
|
-
*
|
|
17
|
-
* assert.isTrue(Optional.isNone(noneValue));
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export const none: None = { $$tag: NoneTypeTagName } as const;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { type Optional, type UnknownOptional } from '../optional.mjs';
|
|
2
|
-
import { isNone } from './optional-is-none.mjs';
|
|
3
|
-
import { type Unwrap } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the `Optional` if it is `Some`, otherwise returns the alternative.
|
|
7
|
-
*
|
|
8
|
-
* Provides a way to chain Optional operations with fallback values. This is
|
|
9
|
-
* particularly useful for implementing default behavior or cascading lookups.
|
|
10
|
-
* Supports both direct usage and curried form for functional composition.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* const preferred = Optional.some('primary');
|
|
16
|
-
*
|
|
17
|
-
* const fallback = Optional.some('secondary');
|
|
18
|
-
*
|
|
19
|
-
* const noneValue = Optional.none as Optional<string>;
|
|
20
|
-
*
|
|
21
|
-
* assert.deepStrictEqual(Optional.orElse(preferred, fallback), preferred);
|
|
22
|
-
*
|
|
23
|
-
* assert.deepStrictEqual(Optional.orElse(noneValue, fallback), fallback);
|
|
24
|
-
*
|
|
25
|
-
* const orElseFallback = Optional.orElse(Optional.some('default'));
|
|
26
|
-
*
|
|
27
|
-
* assert.deepStrictEqual(
|
|
28
|
-
* orElseFallback(Optional.none),
|
|
29
|
-
* Optional.some('default'),
|
|
30
|
-
* );
|
|
31
|
-
*
|
|
32
|
-
* assert.deepStrictEqual(
|
|
33
|
-
* orElseFallback(Optional.some('value')),
|
|
34
|
-
* Optional.some('value'),
|
|
35
|
-
* );
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @template O The input `UnknownOptional` type.
|
|
39
|
-
* @param optional The `Optional` to check.
|
|
40
|
-
* @param alternative The alternative `Optional` to return if the first is
|
|
41
|
-
* `None`.
|
|
42
|
-
* @returns The first `Optional` if `Some`, otherwise the alternative.
|
|
43
|
-
*/
|
|
44
|
-
export function orElse<
|
|
45
|
-
O extends UnknownOptional,
|
|
46
|
-
const O2 extends UnknownOptional,
|
|
47
|
-
>(optional: O, alternative: O2): O | O2;
|
|
48
|
-
|
|
49
|
-
// Curried version
|
|
50
|
-
export function orElse<O2>(
|
|
51
|
-
alternative: Optional<O2>,
|
|
52
|
-
): <O>(optional: Optional<O>) => Optional<O> | Optional<O2>;
|
|
53
|
-
|
|
54
|
-
export function orElse<
|
|
55
|
-
O extends UnknownOptional,
|
|
56
|
-
const O2 extends UnknownOptional,
|
|
57
|
-
>(
|
|
58
|
-
...args: readonly [optional: O, alternative: O2] | readonly [alternative: O2]
|
|
59
|
-
): (O | O2) | ((optional: Optional<Unwrap<O>>) => Optional<Unwrap<O>> | O2) {
|
|
60
|
-
switch (args.length) {
|
|
61
|
-
case 2: {
|
|
62
|
-
const [optional, alternative] = args;
|
|
63
|
-
|
|
64
|
-
return orElseImpl(optional, alternative);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
case 1: {
|
|
68
|
-
// Curried version
|
|
69
|
-
const [alternative] = args;
|
|
70
|
-
|
|
71
|
-
return (optional: Optional<Unwrap<O>>) =>
|
|
72
|
-
orElseImpl(optional, alternative);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const orElseImpl = <
|
|
78
|
-
O extends UnknownOptional,
|
|
79
|
-
const O2 extends UnknownOptional,
|
|
80
|
-
>(
|
|
81
|
-
optional: O,
|
|
82
|
-
alternative: O2,
|
|
83
|
-
): O | O2 => (isNone(optional) ? alternative : optional);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type Some } from '../../../types.mjs';
|
|
2
|
-
import { SomeTypeTagName } from './tag.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates an {@link Some} containing the given value.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* const someValue = Optional.some({ id: 1 });
|
|
11
|
-
*
|
|
12
|
-
* const noneValue = Optional.none;
|
|
13
|
-
*
|
|
14
|
-
* assert.isTrue(Optional.isSome(someValue));
|
|
15
|
-
*
|
|
16
|
-
* assert.isTrue(Optional.isNone(noneValue));
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @template S The type of the value.
|
|
20
|
-
* @param value The value to wrap in an {@link Some}.
|
|
21
|
-
* @returns An {@link Some}<S> containing the value.
|
|
22
|
-
*/
|
|
23
|
-
export const some = <const S,>(value: S): Some<S> =>
|
|
24
|
-
({
|
|
25
|
-
$$tag: SomeTypeTagName,
|
|
26
|
-
value,
|
|
27
|
-
}) as const;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { 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
|
-
* Converts an `Optional` to a nullable value.
|
|
8
|
-
*
|
|
9
|
-
* This function extracts the value from an Optional, returning `undefined`
|
|
10
|
-
* for empty Optionals. This is useful when interfacing with APIs or systems
|
|
11
|
-
* that expect nullable values rather than Optional types.
|
|
12
|
-
*
|
|
13
|
-
* Note: This returns `undefined` (not `null`) for consistency with
|
|
14
|
-
* JavaScript's undefined semantics and TypeScript's optional properties.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* const someNumber = Optional.some(42);
|
|
20
|
-
*
|
|
21
|
-
* const noneNumber = Optional.none as Optional<number>;
|
|
22
|
-
*
|
|
23
|
-
* assert.isTrue(Optional.toNullable(someNumber) === 42);
|
|
24
|
-
*
|
|
25
|
-
* assert.isTrue(Optional.toNullable(noneNumber) === undefined);
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @template O The `UnknownOptional` type to convert.
|
|
29
|
-
* @param optional The `Optional` to convert.
|
|
30
|
-
* @returns The contained value if `Some`, otherwise `undefined`.
|
|
31
|
-
*/
|
|
32
|
-
export const toNullable = <O extends UnknownOptional>(
|
|
33
|
-
optional: O,
|
|
34
|
-
): Unwrap<O> | undefined => (isSome(optional) ? unwrap(optional) : undefined);
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { type Optional, type UnknownOptional } from '../optional.mjs';
|
|
2
|
-
import { unwrap } from './optional-unwrap.mjs';
|
|
3
|
-
import { type Unwrap } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Unwraps an `Optional`, returning the contained value or a default value if
|
|
7
|
-
* it's `None`.
|
|
8
|
-
*
|
|
9
|
-
* Supports both direct usage and curried form for functional composition.
|
|
10
|
-
* This is often preferred over `unwrap()` when you have a sensible fallback
|
|
11
|
-
* value.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* const withValue = Optional.some(5);
|
|
17
|
-
*
|
|
18
|
-
* const withoutValue = Optional.none as Optional<number>;
|
|
19
|
-
*
|
|
20
|
-
* assert.isTrue(Optional.unwrapOr(withValue, 0) === 5);
|
|
21
|
-
*
|
|
22
|
-
* assert.isTrue(Optional.unwrapOr(withoutValue, 0) === 0);
|
|
23
|
-
*
|
|
24
|
-
* const unwrapWithDefault = Optional.unwrapOr(10);
|
|
25
|
-
*
|
|
26
|
-
* assert.isTrue(unwrapWithDefault(Optional.some(3)) === 3);
|
|
27
|
-
*
|
|
28
|
-
* assert.isTrue(unwrapWithDefault(Optional.none) === 10);
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @template O The `UnknownOptional` type to unwrap.
|
|
32
|
-
* @template D The type of the default value.
|
|
33
|
-
* @param optional The `Optional` to unwrap.
|
|
34
|
-
* @param defaultValue The value to return if `optional` is `None`.
|
|
35
|
-
* @returns The contained value if `Some`, otherwise `defaultValue`.
|
|
36
|
-
*/
|
|
37
|
-
export function unwrapOr<O extends UnknownOptional, D>(
|
|
38
|
-
optional: O,
|
|
39
|
-
defaultValue: D,
|
|
40
|
-
): D | Unwrap<O>;
|
|
41
|
-
|
|
42
|
-
// Curried version
|
|
43
|
-
export function unwrapOr<D>(
|
|
44
|
-
defaultValue: D,
|
|
45
|
-
): <O>(optional: Optional<O>) => D | O;
|
|
46
|
-
|
|
47
|
-
export function unwrapOr<O extends UnknownOptional, D>(
|
|
48
|
-
...args: readonly [optional: O, defaultValue: D] | readonly [defaultValue: D]
|
|
49
|
-
): (D | Unwrap<O>) | ((optional: Optional<Unwrap<O>>) => D | Unwrap<O>) {
|
|
50
|
-
switch (args.length) {
|
|
51
|
-
case 2: {
|
|
52
|
-
const [optional, defaultValue] = args;
|
|
53
|
-
|
|
54
|
-
return unwrapOrImpl(optional, defaultValue);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
case 1: {
|
|
58
|
-
// Curried version: first argument is default value
|
|
59
|
-
const [defaultValue] = args;
|
|
60
|
-
|
|
61
|
-
return (optional: Optional<Unwrap<O>>) =>
|
|
62
|
-
unwrapOrImpl(optional, defaultValue);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const unwrapOrImpl = <O extends UnknownOptional, D>(
|
|
68
|
-
optional: O,
|
|
69
|
-
defaultValue: D,
|
|
70
|
-
): D | Unwrap<O> => unwrap(optional) ?? defaultValue;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type UnknownOptional } from '../optional.mjs';
|
|
2
|
-
import { isSome } from './optional-is-some.mjs';
|
|
3
|
-
import { type Unwrap } from './types.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Unwraps an `Optional`, returning the contained value. Throws an error if
|
|
7
|
-
* the `Optional` is `None`.
|
|
8
|
-
*
|
|
9
|
-
* This is a safer alternative to direct value access when you know the
|
|
10
|
-
* Optional should contain a value. Use this method when an empty Optional
|
|
11
|
-
* represents a programming error or unexpected condition.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* const present = Optional.some('available');
|
|
17
|
-
*
|
|
18
|
-
* assert.isTrue(Optional.unwrapThrow(present) === 'available');
|
|
19
|
-
*
|
|
20
|
-
* assert.throws(
|
|
21
|
-
* () => Optional.unwrapThrow(Optional.none),
|
|
22
|
-
* /has failed because it is `None`/u,
|
|
23
|
-
* );
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @template O The `UnknownOptional` type to unwrap.
|
|
27
|
-
* @param optional The `Optional` to unwrap.
|
|
28
|
-
* @returns The contained value if `Some`.
|
|
29
|
-
* @throws {Error} Error with message "`unwrapThrow()` has failed because it
|
|
30
|
-
* is `None`" if the `Optional` is `None`.
|
|
31
|
-
*/
|
|
32
|
-
export const unwrapThrow = <O extends UnknownOptional>(
|
|
33
|
-
optional: O,
|
|
34
|
-
): Unwrap<O> => {
|
|
35
|
-
if (isSome(optional)) {
|
|
36
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
37
|
-
return optional.value as Unwrap<O>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
throw new Error('`unwrapThrow()` has failed because it is `None`');
|
|
41
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { type Some } from '../../../types.mjs';
|
|
2
|
-
import { type UnknownOptional } from '../optional.mjs';
|
|
3
|
-
import { isSome } from './optional-is-some.mjs';
|
|
4
|
-
import { type Unwrap } from './types.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Unwraps an `Optional`, returning the contained value or `undefined` if
|
|
8
|
-
* empty.
|
|
9
|
-
*
|
|
10
|
-
* This function provides a safe way to extract values from Optionals without
|
|
11
|
-
* throwing exceptions. It has overloaded behavior based on the type:
|
|
12
|
-
*
|
|
13
|
-
* - For `Some<T>`: Always returns `T` (guaranteed by type system)
|
|
14
|
-
* - For general `Optional<T>`: Returns `T | undefined`
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* const someString = Optional.some('text');
|
|
20
|
-
*
|
|
21
|
-
* const noneString = Optional.none as Optional<string>;
|
|
22
|
-
*
|
|
23
|
-
* assert.isTrue(Optional.unwrap(someString) === 'text');
|
|
24
|
-
*
|
|
25
|
-
* assert.isTrue(Optional.unwrap(noneString) === undefined);
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @template O The `UnknownOptional` type to unwrap.
|
|
29
|
-
* @param optional The `Optional` to unwrap.
|
|
30
|
-
* @returns The contained value if `Some`, otherwise `undefined`.
|
|
31
|
-
*/
|
|
32
|
-
export function unwrap<O extends Some<unknown>>(optional: O): Unwrap<O>;
|
|
33
|
-
|
|
34
|
-
export function unwrap<O extends UnknownOptional>(
|
|
35
|
-
optional: O,
|
|
36
|
-
): Unwrap<O> | undefined;
|
|
37
|
-
|
|
38
|
-
export function unwrap<O extends UnknownOptional>(
|
|
39
|
-
optional: O,
|
|
40
|
-
): Unwrap<O> | undefined {
|
|
41
|
-
return isSome(optional)
|
|
42
|
-
? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
43
|
-
(optional.value as Unwrap<O>)
|
|
44
|
-
: undefined;
|
|
45
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type Optional } 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
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Combines two `Optional` values into a single `Optional` containing a tuple.
|
|
8
|
-
* If either `Optional` is `None`, returns `None`.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const zipped = Optional.zip(Optional.some('left'), Optional.some(1));
|
|
14
|
-
*
|
|
15
|
-
* assert.isTrue(Optional.isSome(zipped));
|
|
16
|
-
*
|
|
17
|
-
* if (Optional.isSome(zipped)) {
|
|
18
|
-
* const expected: readonly [string, number] = ['left', 1] as const;
|
|
19
|
-
*
|
|
20
|
-
* assert.deepStrictEqual(zipped.value, expected);
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* const missing = Optional.zip(
|
|
24
|
-
* Optional.some('value'),
|
|
25
|
-
* // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
26
|
-
* Optional.none as Optional<number>,
|
|
27
|
-
* );
|
|
28
|
-
*
|
|
29
|
-
* assert.deepStrictEqual(missing, Optional.none);
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @template A The value type of the first `Optional`.
|
|
33
|
-
* @template B The value type of the second `Optional`.
|
|
34
|
-
* @param optionalA The first `Optional`.
|
|
35
|
-
* @param optionalB The second `Optional`.
|
|
36
|
-
* @returns An `Optional` containing a tuple of both values, or `None`.
|
|
37
|
-
*/
|
|
38
|
-
export const zip = <A, const B>(
|
|
39
|
-
optionalA: Optional<A>,
|
|
40
|
-
optionalB: Optional<B>,
|
|
41
|
-
): Optional<readonly [A, B]> =>
|
|
42
|
-
isSome(optionalA) && isSome(optionalB)
|
|
43
|
-
? some([optionalA.value, optionalB.value] as const)
|
|
44
|
-
: none;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** @internal String literal tag to identify the 'Some' variant of Optional. */
|
|
2
|
-
import { type None, type Some } from '../../../types.mjs';
|
|
3
|
-
|
|
4
|
-
export const SomeTypeTagName: Some<unknown>['$$tag'] =
|
|
5
|
-
'ts-data-forge::Optional.some';
|
|
6
|
-
|
|
7
|
-
/** @internal String literal tag to identify the 'None' variant of Optional. */
|
|
8
|
-
export const NoneTypeTagName: None['$$tag'] = 'ts-data-forge::Optional.none';
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type None, type Some } from '../../../types.mjs';
|
|
2
|
-
import { type UnknownOptional } from '../optional.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Extracts the value type `S` from an {@link Some}<S>. If the
|
|
6
|
-
* {@link Optional} is {@link None}, resolves to `never`.
|
|
7
|
-
*
|
|
8
|
-
* @template O The {@link UnknownOptional} type to unwrap.
|
|
9
|
-
*/
|
|
10
|
-
export type Unwrap<O extends UnknownOptional> =
|
|
11
|
-
O extends Some<infer S> ? S : never;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Narrows an {@link UnknownOptional} type to {@link Some}<S> if it is a
|
|
15
|
-
* {@link Some}. If the {@link Optional} is {@link None}, resolves to `never`.
|
|
16
|
-
*
|
|
17
|
-
* @template O The {@link UnknownOptional} type to narrow.
|
|
18
|
-
*/
|
|
19
|
-
export type NarrowToSome<O extends UnknownOptional> = O extends None
|
|
20
|
-
? never
|
|
21
|
-
: O;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Narrows an {@link UnknownOptional} type to {@link None} if it is a
|
|
25
|
-
* {@link None}. If the {@link Optional} is {@link Some}<S>, resolves to never.
|
|
26
|
-
*
|
|
27
|
-
* @template O The {@link UnknownOptional} type to narrow.
|
|
28
|
-
*/
|
|
29
|
-
export type NarrowToNone<O extends UnknownOptional> = O extends None
|
|
30
|
-
? O
|
|
31
|
-
: never;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './optional.mjs';
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type None, type Some } from '../../types.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an optional value that can either be `Some` (containing a value)
|
|
5
|
-
* or `None` (empty).
|
|
6
|
-
*
|
|
7
|
-
* @template S The type of the value that might be present.
|
|
8
|
-
*/
|
|
9
|
-
export type Optional<S> = None | Some<S>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Base type for any {@link Optional}, used for generic constraints. Represents
|
|
13
|
-
* an {@link Optional} with an unknown value type.
|
|
14
|
-
*/
|
|
15
|
-
export type UnknownOptional = None | Some<unknown>;
|
|
16
|
-
|
|
17
|
-
export type { None, Some } from '../../types.mjs';
|
|
18
|
-
|
|
19
|
-
export * as Optional from './impl/index.mjs';
|