ts-data-forge 9.0.0 → 10.0.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 +1 -1
- package/dist/array/impl/array-utils-creation.d.mts +4 -4
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs +17 -112
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +22 -61
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts.map +1 -1
- package/dist/array/impl/array-utils-iterators.mjs +9 -63
- package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +7 -7
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs +78 -78
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +95 -89
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +100 -92
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +31 -141
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +4 -8
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs +11 -12
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +44 -96
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +4 -4
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +150 -292
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +17 -17
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +23 -174
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/array/impl/index.mjs +1 -1
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs +243 -330
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +190 -275
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +1 -1
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +222 -444
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +1 -1
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +158 -324
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +106 -178
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +95 -165
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +2 -0
- package/dist/entry-point.mjs.map +1 -1
- package/dist/expect-type.d.mts +1 -1
- package/dist/expect-type.d.mts.map +1 -1
- package/dist/expect-type.mjs +1 -69
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/match.mjs +9 -9
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs +13 -14
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-filter.mjs +14 -15
- package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs +10 -11
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +1 -25
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +0 -19
- package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +1 -23
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +0 -20
- package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-map.mjs +13 -14
- package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +0 -16
- package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.mjs +10 -11
- package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +2 -21
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +1 -27
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs +9 -10
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +4 -32
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs +4 -4
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +1 -35
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/optional/impl/tag.mjs +2 -3
- package/dist/functional/optional/impl/tag.mjs.map +1 -1
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs +9 -34
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +2 -27
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs +13 -15
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.mjs +16 -16
- package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-fold.mjs +16 -16
- package/dist/functional/result/impl/result-fold.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +4 -31
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +8 -38
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +0 -19
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +0 -19
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +1 -23
- package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
- package/dist/functional/result/impl/result-map-err.mjs +16 -16
- package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-map.mjs +16 -16
- package/dist/functional/result/impl/result-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +2 -27
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-or-else.mjs +10 -12
- package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
- package/dist/functional/result/impl/result-swap.d.mts.map +1 -1
- package/dist/functional/result/impl/result-swap.mjs +4 -22
- package/dist/functional/result/impl/result-swap.mjs.map +1 -1
- package/dist/functional/result/impl/result-to-optional.d.mts.map +1 -1
- package/dist/functional/result/impl/result-to-optional.mjs +0 -27
- package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs +9 -11
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +13 -40
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +4 -32
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs +9 -11
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs +4 -4
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +4 -35
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-zip.d.mts.map +1 -1
- package/dist/functional/result/impl/result-zip.mjs +1 -34
- package/dist/functional/result/impl/result-zip.mjs.map +1 -1
- package/dist/functional/result/impl/tag.mjs +2 -3
- package/dist/functional/result/impl/tag.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/tag.mjs +3 -5
- package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +2 -15
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +13 -13
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +27 -26
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +21 -22
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +4 -20
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +7 -25
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +0 -17
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +1 -25
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +0 -18
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +13 -15
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +18 -18
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +21 -22
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +2 -16
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +9 -9
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +4 -22
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +9 -9
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +12 -27
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +4 -19
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +9 -9
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +4 -5
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +15 -27
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +9 -9
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +10 -24
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +4 -19
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +3 -19
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +14 -45
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/variant-name.d.mts +1 -1
- package/dist/functional/ternary-result/impl/variant-name.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/variant-name.mjs +8 -9
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
- package/dist/guard/as-length-bounded-array.d.mts +117 -0
- package/dist/guard/as-length-bounded-array.d.mts.map +1 -0
- package/dist/guard/as-length-bounded-array.mjs +37 -0
- package/dist/guard/as-length-bounded-array.mjs.map +1 -0
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +0 -41
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/index.d.mts +2 -0
- package/dist/guard/index.d.mts.map +1 -1
- package/dist/guard/index.mjs +2 -0
- package/dist/guard/index.mjs.map +1 -1
- package/dist/guard/is-length-bounded-array.d.mts +159 -0
- package/dist/guard/is-length-bounded-array.d.mts.map +1 -0
- package/dist/guard/is-length-bounded-array.mjs +7 -0
- package/dist/guard/is-length-bounded-array.mjs.map +1 -0
- package/dist/guard/is-length-bounded-string.d.mts +5 -6
- package/dist/guard/is-length-bounded-string.d.mts.map +1 -1
- package/dist/guard/is-length-bounded-string.mjs +0 -157
- package/dist/guard/is-length-bounded-string.mjs.map +1 -1
- package/dist/guard/is-non-empty-string.d.mts +1 -1
- package/dist/guard/is-non-empty-string.d.mts.map +1 -1
- package/dist/guard/is-non-empty-string.mjs +1 -38
- package/dist/guard/is-non-empty-string.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +1 -35
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-primitive.d.mts.map +1 -1
- package/dist/guard/is-primitive.mjs +12 -43
- package/dist/guard/is-primitive.mjs.map +1 -1
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +0 -86
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/guard/is-type.mjs +12 -399
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +0 -40
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/iterator/range.mjs +16 -16
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +52 -340
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +3 -3
- package/dist/number/branded-types/finite-number.mjs +135 -154
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +4 -4
- package/dist/number/branded-types/int.mjs +205 -245
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +15 -15
- package/dist/number/branded-types/int16.mjs +116 -123
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +11 -11
- package/dist/number/branded-types/int32.mjs +116 -123
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +4 -4
- package/dist/number/branded-types/negative-finite-number.mjs +129 -144
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +5 -5
- package/dist/number/branded-types/negative-int.mjs +94 -113
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +5 -5
- package/dist/number/branded-types/negative-safe-int.mjs +103 -124
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +5 -5
- package/dist/number/branded-types/non-negative-finite-number.mjs +136 -142
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +16 -16
- package/dist/number/branded-types/non-negative-int16.mjs +109 -118
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +12 -12
- package/dist/number/branded-types/non-negative-int32.mjs +110 -119
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +3 -3
- package/dist/number/branded-types/non-positive-finite-number.mjs +120 -124
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +4 -4
- package/dist/number/branded-types/non-positive-int.mjs +167 -212
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +4 -4
- package/dist/number/branded-types/non-positive-safe-int.mjs +95 -106
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +4 -4
- package/dist/number/branded-types/non-zero-finite-number.mjs +114 -123
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +2 -2
- package/dist/number/branded-types/non-zero-int.mjs +72 -83
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +7 -7
- package/dist/number/branded-types/non-zero-int16.mjs +96 -107
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +5 -5
- package/dist/number/branded-types/non-zero-int32.mjs +97 -108
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +2 -2
- package/dist/number/branded-types/non-zero-safe-int.mjs +100 -111
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +8 -8
- package/dist/number/branded-types/non-zero-uint16.mjs +96 -107
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +6 -6
- package/dist/number/branded-types/non-zero-uint32.mjs +96 -107
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +8 -8
- package/dist/number/branded-types/positive-finite-number.mjs +139 -141
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +11 -11
- package/dist/number/branded-types/positive-int.mjs +228 -271
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +19 -19
- package/dist/number/branded-types/positive-int16.mjs +109 -118
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +15 -15
- package/dist/number/branded-types/positive-int32.mjs +109 -118
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +11 -11
- package/dist/number/branded-types/positive-safe-int.mjs +244 -275
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +17 -17
- package/dist/number/branded-types/positive-uint16.mjs +109 -118
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +13 -13
- package/dist/number/branded-types/positive-uint32.mjs +110 -119
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +4 -4
- package/dist/number/branded-types/safe-int.mjs +251 -292
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +8 -8
- package/dist/number/branded-types/safe-uint.mjs +111 -119
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +8 -8
- package/dist/number/branded-types/uint.mjs +198 -225
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +14 -14
- package/dist/number/branded-types/uint16.mjs +109 -119
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +10 -10
- package/dist/number/branded-types/uint32.mjs +110 -117
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.mjs +119 -145
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.mjs +107 -121
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/num.d.mts +2 -2
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +76 -537
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +1 -1
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +127 -263
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +107 -222
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/cast-mutable.d.mts.map +1 -1
- package/dist/others/cast-mutable.mjs +8 -37
- package/dist/others/cast-mutable.mjs.map +1 -1
- package/dist/others/cast-readonly.d.mts.map +1 -1
- package/dist/others/cast-readonly.mjs +8 -36
- package/dist/others/cast-readonly.mjs.map +1 -1
- package/dist/others/debounce-function.d.mts.map +1 -1
- package/dist/others/debounce-function.mjs +7 -16
- package/dist/others/debounce-function.mjs.map +1 -1
- package/dist/others/fast-deep-equal.d.mts.map +1 -1
- package/dist/others/fast-deep-equal.mjs +43 -59
- package/dist/others/fast-deep-equal.mjs.map +1 -1
- package/dist/others/if-then.d.mts.map +1 -1
- package/dist/others/if-then.mjs +0 -29
- package/dist/others/if-then.mjs.map +1 -1
- package/dist/others/map-nullable.mjs +9 -9
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/memoize-function.mjs +12 -12
- package/dist/others/memoize-function.mjs.map +1 -1
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +0 -50
- package/dist/others/tuple.mjs.map +1 -1
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs +41 -88
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +4 -49
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +14 -13
- package/src/array/impl/array-utils-creation.mts +3 -3
- package/src/array/impl/array-utils-modification.mts +7 -7
- package/src/array/impl/array-utils-modification.test.mts +4 -4
- package/src/array/impl/array-utils-transformation.mts +4 -4
- package/src/array/impl/array-utils-transformation.test.mts +7 -7
- package/src/array/impl/array-utils-validation.mts +24 -24
- package/src/array/impl/array-utils-validation.test.mts +94 -92
- package/src/collections/queue.test.mts +1 -1
- package/src/guard/as-length-bounded-array.mts +190 -0
- package/src/guard/as-length-bounded-array.test.mts +118 -0
- package/src/guard/index.mts +2 -0
- package/src/guard/is-length-bounded-array.mts +195 -0
- package/src/guard/is-length-bounded-array.test.mts +169 -0
- package/src/guard/is-length-bounded-string.mts +6 -6
- package/src/object/object.test.mts +3 -3
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { unwrapErr } from './result-unwrap-err.mjs';
|
|
2
2
|
|
|
3
3
|
function unwrapErrOr(...args) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return unwrapErrOrImpl(result, defaultValue);
|
|
9
|
-
}
|
|
10
|
-
case 1: {
|
|
11
|
-
// Curried version
|
|
12
|
-
const [defaultValue] = args;
|
|
13
|
-
return (result) => unwrapErrOrImpl(result, defaultValue);
|
|
14
|
-
}
|
|
4
|
+
switch (args.length) {
|
|
5
|
+
case 2: {
|
|
6
|
+
const [result, defaultValue] = args;
|
|
7
|
+
return unwrapErrOrImpl(result, defaultValue);
|
|
15
8
|
}
|
|
9
|
+
case 1: {
|
|
10
|
+
const [defaultValue] = args;
|
|
11
|
+
return (result) => unwrapErrOrImpl(result, defaultValue);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
16
14
|
}
|
|
17
15
|
const unwrapErrOrImpl = (result, defaultValue) => unwrapErr(result) ?? defaultValue;
|
|
18
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-unwrap-err-or.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-err-or.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-unwrap-err-or.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-err-or.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { unwrapErr } from './result-unwrap-err.mjs';\nimport { type UnwrapErr } from './types.mjs';\n\n/**\n * Unwraps a `Result`, returning the error value or a default value if it is\n * `Result.Ok`.\n *\n * @example\n *\n * ```ts\n * const okResult = Result.ok('success');\n *\n * const errResult = Result.err('failure');\n *\n * assert.isTrue(Result.unwrapErrOr(okResult, 'default') === 'default');\n *\n * assert.isTrue(Result.unwrapErrOr(errResult, 'default') === 'failure');\n *\n * const unwrapError = Result.unwrapErrOr('fallback error');\n *\n * assert.isTrue(unwrapError(Result.err('boom')) === 'boom');\n *\n * assert.isTrue(unwrapError(Result.ok('no error')) === 'fallback error');\n * ```\n *\n * @template R The `UnknownResult` type to unwrap.\n * @template D The type of the default value.\n * @param result The `Result` to unwrap.\n * @param defaultValue The value to return if `result` is `Result.Ok`.\n * @returns The error value if `Result.Err`, otherwise `defaultValue`.\n */\nexport function unwrapErrOr<R extends UnknownResult, D>(\n result: R,\n defaultValue: D,\n): D | UnwrapErr<R>;\n\n// Curried version\nexport function unwrapErrOr<D>(\n defaultValue: D,\n): <R extends UnknownResult>(result: R) => D | UnwrapErr<R>;\n\nexport function unwrapErrOr<R extends UnknownResult, D>(\n ...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]\n): D | UnwrapErr<R> | ((result: R) => D | UnwrapErr<R>) {\n switch (args.length) {\n case 2: {\n // Direct version: first argument is result\n const [result, defaultValue] = args;\n\n return unwrapErrOrImpl(result, defaultValue);\n }\n\n case 1: {\n // Curried version\n const [defaultValue] = args;\n\n return (result: R) => unwrapErrOrImpl(result, defaultValue);\n }\n }\n}\n\nconst unwrapErrOrImpl = <R extends UnknownResult, D>(\n result: R,\n defaultValue: D,\n): D | UnwrapErr<R> => unwrapErr(result) ?? defaultValue;\n"],"names":[],"mappings":";;AA0CO,SAAS,eACX,IAAA,EACmD;AACtD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,YAAY,CAAA,GAAI,IAAA;AAE/B,MAAA,OAAO,eAAA,CAAgB,QAAQ,YAAY,CAAA;AAAA,IAC7C;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,YAAY,CAAA,GAAI,IAAA;AAEvB,MAAA,OAAO,CAAC,MAAA,KAAc,eAAA,CAAgB,MAAA,EAAQ,YAAY,CAAA;AAAA,IAC5D;AAAA;AAEJ;AAEA,MAAM,kBAAkB,CACtB,MAAA,EACA,YAAA,KACqB,SAAA,CAAU,MAAM,CAAA,IAAK,YAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-unwrap-err-throw.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-unwrap-err-throw.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"result-unwrap-err-throw.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-unwrap-err-throw.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,aAAa,UAC5C,CAAC,UACF,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,MAAM,KAChC,SAAS,CAAC,CAAC,CAiBb,CAAC"}
|
|
@@ -3,47 +3,20 @@ import { unknownToString } from '../../../others/unknown-to-string.mjs';
|
|
|
3
3
|
import { match } from '../../match.mjs';
|
|
4
4
|
import { isErr } from './result-is-err.mjs';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Unwraps a `Result`, returning the error value. Throws an error if the
|
|
8
|
-
* `Result` is `Result.Ok`.
|
|
9
|
-
*
|
|
10
|
-
* This function is used when you expect a Result to be an error and want to
|
|
11
|
-
* extract the error value. If the Result is unexpectedly Ok, it will throw an
|
|
12
|
-
* error with information about the unexpected success value.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* const errResult = Result.err(new Error('broken'));
|
|
18
|
-
*
|
|
19
|
-
* const okResult = Result.ok('value');
|
|
20
|
-
*
|
|
21
|
-
* assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
22
|
-
*
|
|
23
|
-
* assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
27
|
-
* @param result The `Result` to unwrap.
|
|
28
|
-
* @param toStr An optional function to convert the success value to a string
|
|
29
|
-
* for the error message when the Result is unexpectedly Ok. Defaults to
|
|
30
|
-
* `String`.
|
|
31
|
-
* @returns The error value if `Result.Err`.
|
|
32
|
-
* @throws {Error} Error with message "Expected Err but got Ok: {value}" if
|
|
33
|
-
* the `Result` is `Result.Ok`.
|
|
34
|
-
*/
|
|
35
6
|
const unwrapErrThrow = (result, toStr = unknownToString) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
7
|
+
if (isErr(result)) {
|
|
8
|
+
return result.value;
|
|
9
|
+
}
|
|
10
|
+
const variant = match(result.$$tag, {
|
|
11
|
+
"ts-data-forge::Result.ok": "Ok",
|
|
12
|
+
"ts-data-forge::Result.err": "Err"
|
|
13
|
+
});
|
|
14
|
+
throw new Error(
|
|
15
|
+
`Expected Err but got ${variant}: ${toStr(
|
|
16
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
17
|
+
result.value
|
|
18
|
+
)}`
|
|
19
|
+
);
|
|
47
20
|
};
|
|
48
21
|
|
|
49
22
|
export { unwrapErrThrow };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-unwrap-err-throw.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-err-throw.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-unwrap-err-throw.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-err-throw.mts"],"sourcesContent":["import { unknownToString } from '../../../others/index.mjs';\nimport { match } from '../../match.mjs';\nimport { type UnknownResult } from '../result.mjs';\nimport { isErr } from './result-is-err.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Unwraps a `Result`, returning the error value. Throws an error if the\n * `Result` is `Result.Ok`.\n *\n * This function is used when you expect a Result to be an error and want to\n * extract the error value. If the Result is unexpectedly Ok, it will throw an\n * error with information about the unexpected success value.\n *\n * @example\n *\n * ```ts\n * const errResult = Result.err(new Error('broken'));\n *\n * const okResult = Result.ok('value');\n *\n * assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');\n *\n * assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);\n * ```\n *\n * @template R The `UnknownResult` type to unwrap.\n * @param result The `Result` to unwrap.\n * @param toStr An optional function to convert the success value to a string\n * for the error message when the Result is unexpectedly Ok. Defaults to\n * `String`.\n * @returns The error value if `Result.Err`.\n * @throws {Error} Error with message \"Expected Err but got Ok: {value}\" if\n * the `Result` is `Result.Ok`.\n */\nexport const unwrapErrThrow = <R extends UnknownResult>(\n result: R,\n toStr: (v: UnwrapOk<R>) => string = unknownToString,\n): UnwrapErr<R> => {\n if (isErr(result)) {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return result.value as UnwrapErr<R>;\n }\n\n const variant = match(result.$$tag, {\n 'ts-data-forge::Result.ok': 'Ok',\n 'ts-data-forge::Result.err': 'Err',\n });\n\n throw new Error(\n `Expected Err but got ${variant}: ${toStr(\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n result.value as UnwrapOk<R>,\n )}`,\n );\n};\n"],"names":[],"mappings":";;;;;AAmCO,MAAM,cAAA,GAAiB,CAC5B,MAAA,EACA,KAAA,GAAoC,eAAA,KACnB;AACjB,EAAA,IAAI,KAAA,CAAM,MAAM,CAAA,EAAG;AAEjB,IAAA,OAAO,MAAA,CAAO,KAAA;AAAA,EAChB;AAEA,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,MAAA,CAAO,KAAA,EAAO;AAAA,IAClC,0BAAA,EAA4B,IAAA;AAAA,IAC5B,2BAAA,EAA6B;AAAA,GAC9B,CAAA;AAED,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAAA,qBAAA,EAAwB,OAAO,CAAA,EAAA,EAAK,KAAA;AAAA;AAAA,MAElC,MAAA,CAAO;AAAA,KACR,CAAA;AAAA,GACH;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-unwrap-err.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-unwrap-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"result-unwrap-err.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-unwrap-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,aAAa,UACvC,CAAC,KACR,SAAS,CAAC,CAAC,CAAC,GAAG,SAE0C,CAAC"}
|
|
@@ -1,37 +1,9 @@
|
|
|
1
1
|
import { isErr } from './result-is-err.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* This provides a safe way to extract error values from Results without
|
|
8
|
-
* throwing exceptions. Useful for error handling patterns where you want to
|
|
9
|
-
* check for specific error conditions.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* const okResult = Result.ok('data');
|
|
15
|
-
*
|
|
16
|
-
* const errResult = Result.err('problem');
|
|
17
|
-
*
|
|
18
|
-
* // Result.unwrapErr returns undefined for Ok results
|
|
19
|
-
*
|
|
20
|
-
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
21
|
-
* assert.isTrue(Result.unwrapErr(okResult) === undefined);
|
|
22
|
-
*
|
|
23
|
-
* // Result.unwrapErr returns the error value for Err results
|
|
24
|
-
*
|
|
25
|
-
* assert.isTrue(Result.unwrapErr(errResult) === 'problem');
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
29
|
-
* @param result The `Result` to unwrap.
|
|
30
|
-
* @returns The error value if `Result.Err`, otherwise `undefined`.
|
|
31
|
-
*/
|
|
32
|
-
const unwrapErr = (result) =>
|
|
33
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
34
|
-
isErr(result) ? result.value : undefined;
|
|
3
|
+
const unwrapErr = (result) => (
|
|
4
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
5
|
+
isErr(result) ? result.value : void 0
|
|
6
|
+
);
|
|
35
7
|
|
|
36
8
|
export { unwrapErr };
|
|
37
9
|
//# sourceMappingURL=result-unwrap-err.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-unwrap-err.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-err.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-unwrap-err.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-err.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { isErr } from './result-is-err.mjs';\nimport { type UnwrapErr } from './types.mjs';\n\n/**\n * Unwraps a `Result`, returning the error value or `undefined` if it is\n * `Result.Ok`.\n *\n * This provides a safe way to extract error values from Results without\n * throwing exceptions. Useful for error handling patterns where you want to\n * check for specific error conditions.\n *\n * @example\n *\n * ```ts\n * const okResult = Result.ok('data');\n *\n * const errResult = Result.err('problem');\n *\n * // Result.unwrapErr returns undefined for Ok results\n *\n * // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression\n * assert.isTrue(Result.unwrapErr(okResult) === undefined);\n *\n * // Result.unwrapErr returns the error value for Err results\n *\n * assert.isTrue(Result.unwrapErr(errResult) === 'problem');\n * ```\n *\n * @template R The `UnknownResult` type to unwrap.\n * @param result The `Result` to unwrap.\n * @returns The error value if `Result.Err`, otherwise `undefined`.\n */\nexport const unwrapErr = <R extends UnknownResult>(\n result: R,\n): UnwrapErr<R> | undefined =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n isErr(result) ? (result.value as UnwrapErr<R>) : undefined;\n"],"names":[],"mappings":";;AAiCO,MAAM,YAAY,CACvB,MAAA;AAAA;AAAA,EAGA,KAAA,CAAM,MAAM,CAAA,GAAK,MAAA,CAAO,KAAA,GAAyB;AAAA;;;;"}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { unwrapOk } from './result-unwrap-ok.mjs';
|
|
2
2
|
|
|
3
3
|
function unwrapOkOr(...args) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return unwrapOkOrImpl(result, defaultValue);
|
|
9
|
-
}
|
|
10
|
-
case 1: {
|
|
11
|
-
// Curried version
|
|
12
|
-
const [defaultValue] = args;
|
|
13
|
-
return (result) => unwrapOkOrImpl(result, defaultValue);
|
|
14
|
-
}
|
|
4
|
+
switch (args.length) {
|
|
5
|
+
case 2: {
|
|
6
|
+
const [result, defaultValue] = args;
|
|
7
|
+
return unwrapOkOrImpl(result, defaultValue);
|
|
15
8
|
}
|
|
9
|
+
case 1: {
|
|
10
|
+
const [defaultValue] = args;
|
|
11
|
+
return (result) => unwrapOkOrImpl(result, defaultValue);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
16
14
|
}
|
|
17
15
|
const unwrapOkOrImpl = (result, defaultValue) => unwrapOk(result) ?? defaultValue;
|
|
18
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-unwrap-ok-or.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-ok-or.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-unwrap-ok-or.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-ok-or.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { unwrapOk } from './result-unwrap-ok.mjs';\nimport { type UnwrapOk } from './types.mjs';\n\n/**\n * Unwraps a `Result`, returning the success value or a default value if it is\n * `Result.Err`.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok(10);\n *\n * const errValue = Result.err('fail');\n *\n * assert.isTrue(Result.unwrapOkOr(okValue, 0) === 10);\n *\n * assert.isTrue(Result.unwrapOkOr(errValue, 0) === 0);\n *\n * const unwrapWithDefault = Result.unwrapOkOr(5);\n *\n * assert.isTrue(unwrapWithDefault(Result.ok(3)) === 3);\n *\n * assert.isTrue(unwrapWithDefault(Result.err('no data')) === 5);\n * ```\n *\n * @template R The `UnknownResult` type to unwrap.\n * @template D The type of the default value.\n * @param result The `Result` to unwrap.\n * @param defaultValue The value to return if `result` is `Result.Err`.\n * @returns The success value if `Result.Ok`, otherwise `defaultValue`.\n */\nexport function unwrapOkOr<R extends UnknownResult, D>(\n result: R,\n defaultValue: D,\n): D | UnwrapOk<R>;\n\n// Curried version\nexport function unwrapOkOr<D>(\n defaultValue: D,\n): <R extends UnknownResult>(result: R) => D | UnwrapOk<R>;\n\nexport function unwrapOkOr<R extends UnknownResult, D>(\n ...args: readonly [result: R, defaultValue: D] | readonly [defaultValue: D]\n): D | UnwrapOk<R> | ((result: R) => D | UnwrapOk<R>) {\n switch (args.length) {\n case 2: {\n // Direct version: first argument is result\n const [result, defaultValue] = args;\n\n return unwrapOkOrImpl(result, defaultValue);\n }\n\n case 1: {\n // Curried version\n const [defaultValue] = args;\n\n return (result: R) => unwrapOkOrImpl(result, defaultValue);\n }\n }\n}\n\nconst unwrapOkOrImpl = <R extends UnknownResult, D>(\n result: R,\n defaultValue: D,\n): D | UnwrapOk<R> => unwrapOk(result) ?? defaultValue;\n"],"names":[],"mappings":";;AA0CO,SAAS,cACX,IAAA,EACiD;AACpD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,YAAY,CAAA,GAAI,IAAA;AAE/B,MAAA,OAAO,cAAA,CAAe,QAAQ,YAAY,CAAA;AAAA,IAC5C;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,YAAY,CAAA,GAAI,IAAA;AAEvB,MAAA,OAAO,CAAC,MAAA,KAAc,cAAA,CAAe,MAAA,EAAQ,YAAY,CAAA;AAAA,IAC3D;AAAA;AAEJ;AAEA,MAAM,iBAAiB,CACrB,MAAA,EACA,YAAA,KACoB,QAAA,CAAS,MAAM,CAAA,IAAK,YAAA;;;;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isOk } from './result-is-ok.mjs';
|
|
2
2
|
|
|
3
3
|
function unwrapOk(result) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
return isOk(result) ? (
|
|
5
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
6
|
+
result.value
|
|
7
|
+
) : void 0;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export { unwrapOk };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-unwrap-ok.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-ok.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-unwrap-ok.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-ok.mts"],"sourcesContent":["import { type Ok } from '../../../types.mjs';\nimport { type UnknownResult } from '../result.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { type UnwrapOk } from './types.mjs';\n\n/**\n * Safely unwraps the success value, returning `undefined` for failures.\n *\n * @example\n *\n * ```ts\n * const okResult = Result.ok(42);\n *\n * const errResult = Result.err('oops');\n *\n * // Result.unwrapOk returns the value for Ok results\n *\n * assert.isTrue(Result.unwrapOk(okResult) === 42);\n *\n * // Result.unwrapOk returns undefined for Err results\n *\n * // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression\n * assert.isTrue(Result.unwrapOk(errResult) === undefined);\n * ```\n */\nexport function unwrapOk<R extends Ok<unknown>>(result: R): UnwrapOk<R>;\n\nexport function unwrapOk<R extends UnknownResult>(\n result: R,\n): UnwrapOk<R> | undefined;\n\nexport function unwrapOk<R extends UnknownResult>(\n result: R,\n): UnwrapOk<R> | undefined {\n return isOk(result)\n ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (result.value as UnwrapOk<R>)\n : undefined;\n}\n"],"names":[],"mappings":";;AA+BO,SAAS,SACd,MAAA,EACyB;AACzB,EAAA,OAAO,KAAK,MAAM,CAAA;AAAA;AAAA,IAEb,MAAA,CAAO;AAAA,MACR,MAAA;AACN;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-unwrap-throw.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-unwrap-throw.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"result-unwrap-throw.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-unwrap-throw.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,UACzC,CAAC,UACF,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,MAAM,KACjC,QAAQ,CAAC,CAAC,CAQZ,CAAC"}
|
|
@@ -2,42 +2,11 @@ import '@sindresorhus/is';
|
|
|
2
2
|
import { unknownToString } from '../../../others/unknown-to-string.mjs';
|
|
3
3
|
import { isErr } from './result-is-err.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Unwraps a `Result`, returning the success value. Throws an error if the
|
|
7
|
-
* `Result` is `Result.Err`.
|
|
8
|
-
*
|
|
9
|
-
* This is useful when you're confident that a Result should contain a success
|
|
10
|
-
* value and want to treat errors as exceptional conditions. The error message
|
|
11
|
-
* will be constructed from the error value using the provided string
|
|
12
|
-
* conversion function.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* const okResult = Result.ok('data');
|
|
18
|
-
*
|
|
19
|
-
* const errResult = Result.err(new Error('fail'));
|
|
20
|
-
*
|
|
21
|
-
* assert.isTrue(Result.unwrapThrow(okResult) === 'data');
|
|
22
|
-
*
|
|
23
|
-
* assert.throws(() => Result.unwrapThrow(errResult), Error, 'fail');
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @template R The `UnknownResult` type to unwrap.
|
|
27
|
-
* @param result The `Result` to unwrap.
|
|
28
|
-
* @param toStr An optional function to convert the error value to a string
|
|
29
|
-
* for the error message. Defaults to `String`.
|
|
30
|
-
* @returns The success value if `Result.Ok`.
|
|
31
|
-
* @throws {Error} Error with the stringified error value if the `Result` is
|
|
32
|
-
* `Result.Err`.
|
|
33
|
-
*/
|
|
34
5
|
const unwrapThrow = (result, toStr = unknownToString) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
40
|
-
return result.value;
|
|
6
|
+
if (isErr(result)) {
|
|
7
|
+
throw new Error(toStr(result.value));
|
|
8
|
+
}
|
|
9
|
+
return result.value;
|
|
41
10
|
};
|
|
42
11
|
|
|
43
12
|
export { unwrapThrow };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-unwrap-throw.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-throw.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-unwrap-throw.mjs","sources":["../../../../src/functional/result/impl/result-unwrap-throw.mts"],"sourcesContent":["import { unknownToString } from '../../../others/index.mjs';\nimport { type UnknownResult } from '../result.mjs';\nimport { isErr } from './result-is-err.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Unwraps a `Result`, returning the success value. Throws an error if the\n * `Result` is `Result.Err`.\n *\n * This is useful when you're confident that a Result should contain a success\n * value and want to treat errors as exceptional conditions. The error message\n * will be constructed from the error value using the provided string\n * conversion function.\n *\n * @example\n *\n * ```ts\n * const okResult = Result.ok('data');\n *\n * const errResult = Result.err(new Error('fail'));\n *\n * assert.isTrue(Result.unwrapThrow(okResult) === 'data');\n *\n * assert.throws(() => Result.unwrapThrow(errResult), Error, 'fail');\n * ```\n *\n * @template R The `UnknownResult` type to unwrap.\n * @param result The `Result` to unwrap.\n * @param toStr An optional function to convert the error value to a string\n * for the error message. Defaults to `String`.\n * @returns The success value if `Result.Ok`.\n * @throws {Error} Error with the stringified error value if the `Result` is\n * `Result.Err`.\n */\nexport const unwrapThrow = <R extends UnknownResult>(\n result: R,\n toStr: (e: UnwrapErr<R>) => string = unknownToString,\n): UnwrapOk<R> => {\n if (isErr(result)) {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n throw new Error(toStr(result.value as UnwrapErr<R>));\n }\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return result.value as UnwrapOk<R>;\n};\n"],"names":[],"mappings":";;;;AAkCO,MAAM,WAAA,GAAc,CACzB,MAAA,EACA,KAAA,GAAqC,eAAA,KACrB;AAChB,EAAA,IAAI,KAAA,CAAM,MAAM,CAAA,EAAG;AAEjB,IAAA,MAAM,IAAI,KAAA,CAAM,KAAA,CAAM,MAAA,CAAO,KAAqB,CAAC,CAAA;AAAA,EACrD;AAGA,EAAA,OAAO,MAAA,CAAO,KAAA;AAChB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-zip.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-zip.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,GAAG,GAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"result-zip.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-zip.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,GAAG,GAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,WACvB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,WACd,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,KACtB,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,CAKvB,CAAC"}
|
|
@@ -1,40 +1,7 @@
|
|
|
1
1
|
import { isOk } from './result-is-ok.mjs';
|
|
2
2
|
import { ok } from './result-ok.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Combines two `Result` values into a single `Result` containing a tuple. If
|
|
6
|
-
* either `Result` is `Err`, returns the first `Err` encountered.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const first = Result.ok('left');
|
|
12
|
-
*
|
|
13
|
-
* const second = Result.ok(1);
|
|
14
|
-
*
|
|
15
|
-
* const expected = ['left', 1] as const;
|
|
16
|
-
*
|
|
17
|
-
* assert.deepStrictEqual(Result.zip(first, second), Result.ok(expected));
|
|
18
|
-
*
|
|
19
|
-
* assert.deepStrictEqual(
|
|
20
|
-
* Result.zip(first, Result.err('error')),
|
|
21
|
-
* Result.err('error'),
|
|
22
|
-
* );
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @template S1 The success type of the first `Result`.
|
|
26
|
-
* @template E1 The error type of the first `Result`.
|
|
27
|
-
* @template S2 The success type of the second `Result`.
|
|
28
|
-
* @template E2 The error type of the second `Result`.
|
|
29
|
-
* @param resultA The first `Result`.
|
|
30
|
-
* @param resultB The second `Result`.
|
|
31
|
-
* @returns A `Result` containing a tuple of both values, or the first `Err`.
|
|
32
|
-
*/
|
|
33
|
-
const zip = (resultA, resultB) => isOk(resultA)
|
|
34
|
-
? isOk(resultB)
|
|
35
|
-
? ok([resultA.value, resultB.value])
|
|
36
|
-
: resultB
|
|
37
|
-
: resultA;
|
|
4
|
+
const zip = (resultA, resultB) => isOk(resultA) ? isOk(resultB) ? ok([resultA.value, resultB.value]) : resultB : resultA;
|
|
38
5
|
|
|
39
6
|
export { zip };
|
|
40
7
|
//# sourceMappingURL=result-zip.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-zip.mjs","sources":["../../../../src/functional/result/impl/result-zip.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-zip.mjs","sources":["../../../../src/functional/result/impl/result-zip.mts"],"sourcesContent":["import { type Result } from '../result.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { ok } from './result-ok.mjs';\n\n/**\n * Combines two `Result` values into a single `Result` containing a tuple. If\n * either `Result` is `Err`, returns the first `Err` encountered.\n *\n * @example\n *\n * ```ts\n * const first = Result.ok('left');\n *\n * const second = Result.ok(1);\n *\n * const expected = ['left', 1] as const;\n *\n * assert.deepStrictEqual(Result.zip(first, second), Result.ok(expected));\n *\n * assert.deepStrictEqual(\n * Result.zip(first, Result.err('error')),\n * Result.err('error'),\n * );\n * ```\n *\n * @template S1 The success type of the first `Result`.\n * @template E1 The error type of the first `Result`.\n * @template S2 The success type of the second `Result`.\n * @template E2 The error type of the second `Result`.\n * @param resultA The first `Result`.\n * @param resultB The second `Result`.\n * @returns A `Result` containing a tuple of both values, or the first `Err`.\n */\nexport const zip = <S1, E1, S2, E2>(\n resultA: Result<S1, E1>,\n resultB: Result<S2, E2>,\n): Result<readonly [S1, S2], E1 | E2> =>\n isOk(resultA)\n ? isOk(resultB)\n ? ok([resultA.value, resultB.value] as const)\n : resultB\n : resultA;\n"],"names":[],"mappings":";;;AAiCO,MAAM,MAAM,CACjB,OAAA,EACA,YAEA,IAAA,CAAK,OAAO,IACR,IAAA,CAAK,OAAO,CAAA,GACV,EAAA,CAAG,CAAC,OAAA,CAAQ,KAAA,EAAO,QAAQ,KAAK,CAAU,IAC1C,OAAA,GACF;;;;"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const OkTypeTagName =
|
|
2
|
-
|
|
3
|
-
const ErrTypeTagName = 'ts-data-forge::Result.err';
|
|
1
|
+
const OkTypeTagName = "ts-data-forge::Result.ok";
|
|
2
|
+
const ErrTypeTagName = "ts-data-forge::Result.err";
|
|
4
3
|
|
|
5
4
|
export { ErrTypeTagName, OkTypeTagName };
|
|
6
5
|
//# sourceMappingURL=tag.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.mjs","sources":["../../../../src/functional/result/impl/tag.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"tag.mjs","sources":["../../../../src/functional/result/impl/tag.mts"],"sourcesContent":["/** @internal Tag identifying the Ok variant. */\nimport { type Err, type Ok } from '../../../types.mjs';\n\nexport const OkTypeTagName: Ok<unknown>['$$tag'] = 'ts-data-forge::Result.ok';\n\n/** @internal Tag identifying the Err variant. */\nexport const ErrTypeTagName: Err<unknown>['$$tag'] =\n 'ts-data-forge::Result.err';\n"],"names":[],"mappings":"AAGO,MAAM,aAAA,GAAsC;AAG5C,MAAM,cAAA,GACX;;;;"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const OkTypeTagName =
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
/** @internal Tag identifying the Err variant. */
|
|
5
|
-
const ErrTypeTagName = 'ts-data-forge::Result.err';
|
|
1
|
+
const OkTypeTagName = "ts-data-forge::Result.ok";
|
|
2
|
+
const WarnTypeTagName = "ts-data-forge::Result.warn";
|
|
3
|
+
const ErrTypeTagName = "ts-data-forge::Result.err";
|
|
6
4
|
|
|
7
5
|
export { ErrTypeTagName, OkTypeTagName, WarnTypeTagName };
|
|
8
6
|
//# sourceMappingURL=tag.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.mjs","sources":["../../../../src/functional/ternary-result/impl/tag.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"tag.mjs","sources":["../../../../src/functional/ternary-result/impl/tag.mts"],"sourcesContent":["/** @internal Tag identifying the Ok variant. */\nimport {\n type TernaryErr,\n type TernaryOk,\n type TernaryWarn,\n} from '../ternary-result.mjs';\n\nexport const OkTypeTagName: TernaryOk<unknown>['$$tag'] =\n 'ts-data-forge::Result.ok';\n\n/** @internal Tag identifying the Warn variant. */\nexport const WarnTypeTagName: TernaryWarn<unknown, unknown>['$$tag'] =\n 'ts-data-forge::Result.warn';\n\n/** @internal Tag identifying the Err variant. */\nexport const ErrTypeTagName: TernaryErr<unknown>['$$tag'] =\n 'ts-data-forge::Result.err';\n"],"names":[],"mappings":"AAOO,MAAM,aAAA,GACX;AAGK,MAAM,eAAA,GACX;AAGK,MAAM,cAAA,GACX;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ternary-result-err.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,GAAG,GAAI,KAAK,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"ternary-result-err.d.mts","sourceRoot":"","sources":["../../../../src/functional/ternary-result/impl/ternary-result-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,GAAG,GAAI,KAAK,CAAC,CAAC,SAAU,CAAC,KAAG,UAAU,CAAC,CAAC,CAIxC,CAAC"}
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import { ErrTypeTagName } from './tag.mjs';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Creates a `TernaryResult.Err` containing the provided error value.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* const failure = TernaryResult.err(new Error('missing data'));
|
|
10
|
-
*
|
|
11
|
-
* assert.strictEqual(failure.$$tag, 'ts-data-forge::Result.err');
|
|
12
|
-
*
|
|
13
|
-
* assert.isTrue(TernaryResult.isErr(failure));
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
3
|
const err = (value) => ({
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
$$tag: ErrTypeTagName,
|
|
5
|
+
value
|
|
19
6
|
});
|
|
20
7
|
|
|
21
8
|
export { err };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ternary-result-err.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-err.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"ternary-result-err.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-err.mts"],"sourcesContent":["import { type TernaryErr } from '../ternary-result.mjs';\nimport { ErrTypeTagName } from './tag.mjs';\n\n/**\n * Creates a `TernaryResult.Err` containing the provided error value.\n *\n * @example\n *\n * ```ts\n * const failure = TernaryResult.err(new Error('missing data'));\n *\n * assert.strictEqual(failure.$$tag, 'ts-data-forge::Result.err');\n *\n * assert.isTrue(TernaryResult.isErr(failure));\n * ```\n */\nexport const err = <const E,>(value: E): TernaryErr<E> =>\n ({\n $$tag: ErrTypeTagName,\n value,\n }) as const;\n"],"names":[],"mappings":";;AAgBO,MAAM,GAAA,GAAM,CAAW,KAAA,MAC3B;AAAA,EACC,KAAA,EAAO,cAAA;AAAA,EACP;AACF,CAAA;;;;"}
|
|
@@ -2,22 +2,22 @@ import { isOk } from './ternary-result-is-ok.mjs';
|
|
|
2
2
|
import { unwrapOk } from './ternary-result-unwrap-ok.mjs';
|
|
3
3
|
|
|
4
4
|
function expectToBe(...args) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
case 1: {
|
|
11
|
-
const [message] = args;
|
|
12
|
-
return (result) => expectImpl(result, message);
|
|
13
|
-
}
|
|
5
|
+
switch (args.length) {
|
|
6
|
+
case 2: {
|
|
7
|
+
const [result, message] = args;
|
|
8
|
+
return expectImpl(result, message);
|
|
14
9
|
}
|
|
10
|
+
case 1: {
|
|
11
|
+
const [message] = args;
|
|
12
|
+
return (result) => expectImpl(result, message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
16
|
const expectImpl = (result, message) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (isOk(result)) {
|
|
18
|
+
return unwrapOk(result);
|
|
19
|
+
}
|
|
20
|
+
throw new Error(message);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export { expectToBe };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ternary-result-expect-to-be.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-expect-to-be.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"ternary-result-expect-to-be.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-expect-to-be.mts"],"sourcesContent":["import {\n type TernaryResult,\n type UnknownTernaryResult,\n} from '../ternary-result.mjs';\nimport { isOk } from './ternary-result-is-ok.mjs';\nimport { unwrapOk } from './ternary-result-unwrap-ok.mjs';\nimport { type UnwrapOk } from './types.mjs';\n\n/**\n * Unwraps the Ok value or throws with the provided message.\n *\n * @example\n *\n * ```ts\n * const okValue = TernaryResult.ok('ready');\n *\n * assert.strictEqual(TernaryResult.expectToBe(okValue, 'missing'), 'ready');\n *\n * const expectResult = TernaryResult.expectToBe('needs value');\n *\n * const throwTest = (): void => {\n * expectResult(TernaryResult.err('oops'));\n * };\n *\n * assert.throws(throwTest, /needs value/u);\n * ```\n */\nexport function expectToBe<R extends UnknownTernaryResult>(\n result: R,\n message: string,\n): UnwrapOk<R>;\n\n// Curried version\nexport function expectToBe(\n message: string,\n): <S, W, E>(result: TernaryResult<S, E, W>) => S;\n\nexport function expectToBe<R extends UnknownTernaryResult>(\n ...args: readonly [result: R, message: string] | readonly [message: string]\n): UnwrapOk<R> | ((result: R) => UnwrapOk<R>) {\n switch (args.length) {\n case 2: {\n const [result, message] = args;\n\n return expectImpl(result, message);\n }\n\n case 1: {\n const [message] = args;\n\n return (result: R) => expectImpl(result, message);\n }\n }\n}\n\nconst expectImpl = <R extends UnknownTernaryResult>(\n result: R,\n message: string,\n): UnwrapOk<R> => {\n if (isOk(result)) {\n return unwrapOk(result);\n }\n\n throw new Error(message);\n};\n"],"names":[],"mappings":";;;AAqCO,SAAS,cACX,IAAA,EACyC;AAC5C,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,MAAA,EAAQ,OAAO,CAAA,GAAI,IAAA;AAE1B,MAAA,OAAO,UAAA,CAAW,QAAQ,OAAO,CAAA;AAAA,IACnC;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,OAAO,CAAA,GAAI,IAAA;AAElB,MAAA,OAAO,CAAC,MAAA,KAAc,UAAA,CAAW,MAAA,EAAQ,OAAO,CAAA;AAAA,IAClD;AAAA;AAEJ;AAEA,MAAM,UAAA,GAAa,CACjB,MAAA,EACA,OAAA,KACgB;AAChB,EAAA,IAAI,IAAA,CAAK,MAAM,CAAA,EAAG;AAChB,IAAA,OAAO,SAAS,MAAM,CAAA;AAAA,EACxB;AAEA,EAAA,MAAM,IAAI,MAAM,OAAO,CAAA;AACzB,CAAA;;;;"}
|
|
@@ -3,38 +3,39 @@ import { isWarn } from './ternary-result-is-warn.mjs';
|
|
|
3
3
|
import { warn } from './ternary-result-warn.mjs';
|
|
4
4
|
|
|
5
5
|
function flatMap(...args) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
case 1: {
|
|
12
|
-
const [flatMapFn] = args;
|
|
13
|
-
return (result) => flatMapImpl(result, flatMapFn);
|
|
14
|
-
}
|
|
6
|
+
switch (args.length) {
|
|
7
|
+
case 2: {
|
|
8
|
+
const [result, flatMapFn] = args;
|
|
9
|
+
return flatMapImpl(result, flatMapFn);
|
|
15
10
|
}
|
|
11
|
+
case 1: {
|
|
12
|
+
const [flatMapFn] = args;
|
|
13
|
+
return (result) => flatMapImpl(result, flatMapFn);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
const flatMapImpl = (result, flatMapFn) => {
|
|
18
|
-
|
|
18
|
+
if (isOk(result)) {
|
|
19
|
+
return flatMapFn(result.value);
|
|
20
|
+
}
|
|
21
|
+
if (isWarn(result)) {
|
|
22
|
+
const next = flatMapFn(
|
|
23
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
24
|
+
result.value
|
|
25
|
+
);
|
|
26
|
+
if (isOk(next)) {
|
|
27
|
+
return warn(
|
|
28
|
+
next.value,
|
|
19
29
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
20
|
-
|
|
30
|
+
result.warning
|
|
31
|
+
);
|
|
21
32
|
}
|
|
22
|
-
if (isWarn(
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
25
|
-
result.value);
|
|
26
|
-
if (isOk(next)) {
|
|
27
|
-
return warn(next.value,
|
|
28
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
29
|
-
result.warning);
|
|
30
|
-
}
|
|
31
|
-
if (isWarn(next)) {
|
|
32
|
-
return warn(next.value, next.warning);
|
|
33
|
-
}
|
|
34
|
-
return next;
|
|
33
|
+
if (isWarn(next)) {
|
|
34
|
+
return warn(next.value, next.warning);
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
return next;
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
export { flatMap };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ternary-result-flat-map.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-flat-map.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"ternary-result-flat-map.mjs","sources":["../../../../src/functional/ternary-result/impl/ternary-result-flat-map.mts"],"sourcesContent":["import {\n type TernaryErr,\n type TernaryResult,\n type UnknownTernaryResult,\n} from '../ternary-result.mjs';\nimport { isOk } from './ternary-result-is-ok.mjs';\nimport { isWarn } from './ternary-result-is-warn.mjs';\nimport { warn } from './ternary-result-warn.mjs';\nimport { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';\n\n/**\n * Applies a function returning a `TernaryResult` to the Ok variant.\n *\n * @example\n *\n * ```ts\n * const parse = (value: string): TernaryResult<number, string, string> =>\n * pipe(Num.safeParseFloat(value)).map((result) =>\n * Result.isErr(result)\n * ? TernaryResult.err('NaN')\n * : TernaryResult.ok(result.value),\n * ).value;\n *\n * const doubled = TernaryResult.flatMap(TernaryResult.ok('3'), (text) =>\n * TernaryResult.map(parse(text), (num) => num * 2),\n * );\n *\n * const warnPassthrough = TernaryResult.flatMap(\n * TernaryResult.warn('3', 'retry'),\n * parse,\n * );\n *\n * const errPassthrough = TernaryResult.flatMap(\n * TernaryResult.err('oops'),\n * parse,\n * );\n *\n * assert.deepStrictEqual(doubled, TernaryResult.ok(6));\n *\n * assert.deepStrictEqual(warnPassthrough, TernaryResult.warn(3, 'retry'));\n *\n * assert.deepStrictEqual(errPassthrough, TernaryResult.err('oops'));\n * ```\n */\nexport function flatMap<R extends UnknownTernaryResult, S2, W2, E2>(\n result: R,\n flatMapFn: (value: UnwrapOk<R>) => TernaryResult<S2, E2, W2>,\n): TernaryResult<S2, E2 | UnwrapErr<R>, W2 | UnwrapWarn<R>>;\n\n// Curried version\nexport function flatMap<S, S2, W2, E2>(\n flatMapFn: (value: S) => TernaryResult<S2, E2, W2>,\n): <W, E>(result: TernaryResult<S, E, W>) => TernaryResult<S2, E | E2, W | W2>;\n\nexport function flatMap<R extends UnknownTernaryResult, S2, W2, E2>(\n ...args:\n | readonly [\n result: R,\n flatMapFn: (value: UnwrapOk<R>) => TernaryResult<S2, E2, W2>,\n ]\n | readonly [flatMapFn: (value: UnwrapOk<R>) => TernaryResult<S2, E2, W2>]\n):\n | TernaryResult<S2, E2 | UnwrapErr<R>, W2 | UnwrapWarn<R>>\n | ((result: R) => TernaryResult<S2, UnwrapErr<R> | E2, UnwrapWarn<R> | W2>) {\n switch (args.length) {\n case 2: {\n const [result, flatMapFn] = args;\n\n return flatMapImpl(result, flatMapFn);\n }\n\n case 1: {\n const [flatMapFn] = args;\n\n return (result: R) => flatMapImpl(result, flatMapFn);\n }\n }\n}\n\nconst flatMapImpl = <R extends UnknownTernaryResult, S2, W2, E2>(\n result: R,\n flatMapFn: (value: UnwrapOk<R>) => TernaryResult<S2, E2, W2>,\n): TernaryResult<S2, E2 | UnwrapErr<R>, W2 | UnwrapWarn<R>> => {\n if (isOk(result)) {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return flatMapFn(result.value as UnwrapOk<R>);\n }\n\n if (isWarn(result)) {\n const next = flatMapFn(\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n result.value as UnwrapOk<R>,\n );\n\n if (isOk(next)) {\n return warn(\n next.value,\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n result.warning as UnwrapWarn<R>,\n );\n }\n\n if (isWarn(next)) {\n return warn(next.value, next.warning satisfies W2 | UnwrapWarn<R>);\n }\n\n return next;\n }\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return result as TernaryErr<E2 | UnwrapErr<R>>;\n};\n"],"names":[],"mappings":";;;;AAsDO,SAAS,WACX,IAAA,EAQyE;AAC5E,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,IAAA;AAE5B,MAAA,OAAO,WAAA,CAAY,QAAQ,SAAS,CAAA;AAAA,IACtC;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,SAAS,CAAA,GAAI,IAAA;AAEpB,MAAA,OAAO,CAAC,MAAA,KAAc,WAAA,CAAY,MAAA,EAAQ,SAAS,CAAA;AAAA,IACrD;AAAA;AAEJ;AAEA,MAAM,WAAA,GAAc,CAClB,MAAA,EACA,SAAA,KAC6D;AAC7D,EAAA,IAAI,IAAA,CAAK,MAAM,CAAA,EAAG;AAEhB,IAAA,OAAO,SAAA,CAAU,OAAO,KAAoB,CAAA;AAAA,EAC9C;AAEA,EAAA,IAAI,MAAA,CAAO,MAAM,CAAA,EAAG;AAClB,IAAA,MAAM,IAAA,GAAO,SAAA;AAAA;AAAA,MAEX,MAAA,CAAO;AAAA,KACT;AAEA,IAAA,IAAI,IAAA,CAAK,IAAI,CAAA,EAAG;AACd,MAAA,OAAO,IAAA;AAAA,QACL,IAAA,CAAK,KAAA;AAAA;AAAA,QAEL,MAAA,CAAO;AAAA,OACT;AAAA,IACF;AAEA,IAAA,IAAI,MAAA,CAAO,IAAI,CAAA,EAAG;AAChB,MAAA,OAAO,IAAA,CAAK,IAAA,CAAK,KAAA,EAAO,IAAA,CAAK,OAAoC,CAAA;AAAA,IACnE;AAEA,IAAA,OAAO,IAAA;AAAA,EACT;AAGA,EAAA,OAAO,MAAA;AACT,CAAA;;;;"}
|