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
|
@@ -3,24 +3,24 @@ import { isOk } from './result-is-ok.mjs';
|
|
|
3
3
|
import { ok } from './result-ok.mjs';
|
|
4
4
|
|
|
5
5
|
function fold(...args) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return foldImpl(result, mapFn, mapErrFn);
|
|
11
|
-
}
|
|
12
|
-
case 2: {
|
|
13
|
-
// Curried version
|
|
14
|
-
const [mapFn, mapErrFn] = args;
|
|
15
|
-
return (result) => foldImpl(result, mapFn, mapErrFn);
|
|
16
|
-
}
|
|
6
|
+
switch (args.length) {
|
|
7
|
+
case 3: {
|
|
8
|
+
const [result, mapFn, mapErrFn] = args;
|
|
9
|
+
return foldImpl(result, mapFn, mapErrFn);
|
|
17
10
|
}
|
|
11
|
+
case 2: {
|
|
12
|
+
const [mapFn, mapErrFn] = args;
|
|
13
|
+
return (result) => foldImpl(result, mapFn, mapErrFn);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
18
16
|
}
|
|
19
|
-
const foldImpl = (result, mapFn, mapErrFn) => isOk(result)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
const foldImpl = (result, mapFn, mapErrFn) => isOk(result) ? (
|
|
18
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
19
|
+
ok(mapFn(result.value))
|
|
20
|
+
) : (
|
|
21
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
22
|
+
err(mapErrFn(result.value))
|
|
23
|
+
);
|
|
24
24
|
|
|
25
25
|
export { fold };
|
|
26
26
|
//# sourceMappingURL=result-fold.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-fold.mjs","sources":["../../../../src/functional/result/impl/result-fold.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-fold.mjs","sources":["../../../../src/functional/result/impl/result-fold.mts"],"sourcesContent":["import { type Result, type UnknownResult } from '../result.mjs';\nimport { err } from './result-err.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { ok } from './result-ok.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Applies one of two functions depending on whether the `Result` is `Ok` or\n * `Err`.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok(2);\n *\n * const errValue = Result.err('bad');\n *\n * const foldedOk = Result.fold(\n * okValue,\n * (value) => value * 2,\n * (error) => error,\n * );\n *\n * const foldedErr = Result.fold(\n * errValue,\n * (value: number) => value * 2,\n * (error) => error.toUpperCase(),\n * );\n *\n * assert.deepStrictEqual(foldedOk, Result.ok(4));\n *\n * assert.deepStrictEqual(foldedErr, Result.err('BAD'));\n *\n * const foldNumbers = Result.fold(\n * (value: number) => value * 3,\n * (error: string) => error.length,\n * );\n *\n * assert.deepStrictEqual(foldNumbers(Result.ok(3)), Result.ok(9));\n *\n * assert.deepStrictEqual(foldNumbers(Result.err('oops')), Result.err(4));\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @template S2 The type of the success value returned by `mapFn`.\n * @template E2 The type of the error value returned by `mapErrFn`.\n * @param result The `Result` to fold.\n * @param mapFn The function to apply if `result` is `Ok`.\n * @param mapErrFn The function to apply if `result` is `Err`.\n * @returns A new `Result<S2, E2>` based on the applied function.\n */\nexport function fold<R extends UnknownResult, S2, E2>(\n result: R,\n mapFn: (value: UnwrapOk<R>) => S2,\n mapErrFn: (error: UnwrapErr<R>) => E2,\n): Result<S2, E2>;\n\n// Curried version\nexport function fold<S, E, S2, E2>(\n mapFn: (value: S) => S2,\n mapErrFn: (error: E) => E2,\n): (result: Result<S, E>) => Result<S2, E2>;\n\nexport function fold<R extends UnknownResult, S2, E2>(\n ...args:\n | readonly [\n result: R,\n mapFn: (value: UnwrapOk<R>) => S2,\n mapErrFn: (error: UnwrapErr<R>) => E2,\n ]\n | readonly [\n mapFn: (value: UnwrapOk<R>) => S2,\n mapErrFn: (error: UnwrapErr<R>) => E2,\n ]\n): Result<S2, E2> | ((result: R) => Result<S2, E2>) {\n switch (args.length) {\n case 3: {\n // Direct version: first argument is result\n const [result, mapFn, mapErrFn] = args;\n\n return foldImpl(result, mapFn, mapErrFn);\n }\n\n case 2: {\n // Curried version\n const [mapFn, mapErrFn] = args;\n\n return (result: R) => foldImpl(result, mapFn, mapErrFn);\n }\n }\n}\n\nconst foldImpl = <R extends UnknownResult, S2, E2>(\n result: R,\n mapFn: (value: UnwrapOk<R>) => S2,\n mapErrFn: (error: UnwrapErr<R>) => E2,\n): Result<S2, E2> =>\n isOk(result)\n ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n ok(mapFn(result.value as UnwrapOk<R>))\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n err(mapErrFn(result.value as UnwrapErr<R>));\n"],"names":[],"mappings":";;;;AA+DO,SAAS,QACX,IAAA,EAU+C;AAClD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAA,EAAO,QAAQ,CAAA,GAAI,IAAA;AAElC,MAAA,OAAO,QAAA,CAAS,MAAA,EAAQ,KAAA,EAAO,QAAQ,CAAA;AAAA,IACzC;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,IAAA;AAE1B,MAAA,OAAO,CAAC,MAAA,KAAc,QAAA,CAAS,MAAA,EAAQ,OAAO,QAAQ,CAAA;AAAA,IACxD;AAAA;AAEJ;AAEA,MAAM,WAAW,CACf,MAAA,EACA,KAAA,EACA,QAAA,KAEA,KAAK,MAAM,CAAA;AAAA;AAAA,EAEP,EAAA,CAAG,KAAA,CAAM,MAAA,CAAO,KAAoB,CAAC;AAAA;AAAA;AAAA,EAErC,GAAA,CAAI,QAAA,CAAS,MAAA,CAAO,KAAqB,CAAC;AAAA,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-from-promise.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-from-promise.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C;;;;GAIG;AACH,KAAK,aAAa,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,IAC3C,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"result-from-promise.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-from-promise.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C;;;;GAIG;AACH,KAAK,aAAa,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,IAC3C,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,WAC3C,CAAC,KACT,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAEmB,CAAC"}
|
|
@@ -1,37 +1,10 @@
|
|
|
1
1
|
import { err } from './result-err.mjs';
|
|
2
2
|
import { ok } from './result-ok.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* reason.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const successPromise = Result.fromPromise(Promise.resolve('ok'));
|
|
14
|
-
*
|
|
15
|
-
* const failurePromise = Result.fromPromise(
|
|
16
|
-
* Promise.reject(new Error('fail')),
|
|
17
|
-
* );
|
|
18
|
-
*
|
|
19
|
-
* const resolved = await successPromise;
|
|
20
|
-
*
|
|
21
|
-
* const rejected = await failurePromise;
|
|
22
|
-
*
|
|
23
|
-
* assert.deepStrictEqual(resolved, Result.ok('ok'));
|
|
24
|
-
*
|
|
25
|
-
* assert.isTrue(Result.isErr(rejected));
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @template P The type of the input Promise.
|
|
29
|
-
* @param promise The Promise to convert.
|
|
30
|
-
* @returns A Promise that resolves to `Result<UnwrapPromise<P>, unknown>`.
|
|
31
|
-
*/
|
|
32
|
-
const fromPromise = (promise) =>
|
|
33
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
34
|
-
promise.then((v) => ok(v)).catch(err);
|
|
4
|
+
const fromPromise = (promise) => (
|
|
5
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
6
|
+
promise.then((v) => ok(v)).catch(err)
|
|
7
|
+
);
|
|
35
8
|
|
|
36
9
|
export { fromPromise };
|
|
37
10
|
//# sourceMappingURL=result-from-promise.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-from-promise.mjs","sources":["../../../../src/functional/result/impl/result-from-promise.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-from-promise.mjs","sources":["../../../../src/functional/result/impl/result-from-promise.mts"],"sourcesContent":["import { type Ok } from '../../../types.mjs';\nimport { type Result } from '../result.mjs';\nimport { err } from './result-err.mjs';\nimport { ok } from './result-ok.mjs';\n\n/**\n * @template P The Promise type.\n * @internal\n * Utility type to extract the resolved value type from a Promise.\n */\ntype UnwrapPromise<P extends Promise<unknown>> =\n P extends Promise<infer V> ? V : never;\n\n/**\n * Converts a Promise into a Promise that resolves to a `Result`. If the input\n * Promise resolves, the `Result` will be `Ok` with the resolved value. If the\n * input Promise rejects, the `Result` will be `Err` with the rejection\n * reason.\n *\n * @example\n *\n * ```ts\n * const successPromise = Result.fromPromise(Promise.resolve('ok'));\n *\n * const failurePromise = Result.fromPromise(\n * Promise.reject(new Error('fail')),\n * );\n *\n * const resolved = await successPromise;\n *\n * const rejected = await failurePromise;\n *\n * assert.deepStrictEqual(resolved, Result.ok('ok'));\n *\n * assert.isTrue(Result.isErr(rejected));\n * ```\n *\n * @template P The type of the input Promise.\n * @param promise The Promise to convert.\n * @returns A Promise that resolves to `Result<UnwrapPromise<P>, unknown>`.\n */\nexport const fromPromise = <P extends Promise<unknown>>(\n promise: P,\n): Promise<Result<UnwrapPromise<P>, unknown>> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n promise.then((v) => ok(v) as Ok<UnwrapPromise<P>>).catch(err);\n"],"names":[],"mappings":";;;AAyCO,MAAM,cAAc,CACzB,OAAA;AAAA;AAAA,EAGA,OAAA,CAAQ,KAAK,CAAC,CAAA,KAAM,GAAG,CAAC,CAAyB,CAAA,CAAE,KAAA,CAAM,GAAG;AAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-from-throwable.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-from-throwable.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"result-from-throwable.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-from-throwable.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,MAAO,MAAM,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,KAAK,CAY9D,CAAC"}
|
|
@@ -3,46 +3,16 @@ import { unknownToString } from '../../../others/unknown-to-string.mjs';
|
|
|
3
3
|
import { err } from './result-err.mjs';
|
|
4
4
|
import { ok } from './result-ok.mjs';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Wraps a function that may throw an exception in a `Result`.
|
|
8
|
-
*
|
|
9
|
-
* This is a fundamental utility for converting traditional exception-based
|
|
10
|
-
* error handling into Result-based error handling. Any thrown value is
|
|
11
|
-
* converted to an Error object for consistent error handling.
|
|
12
|
-
*
|
|
13
|
-
* If the function executes successfully, returns `Result.Ok` with the result.
|
|
14
|
-
* If the function throws, returns `Result.Err` with the caught error.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* const success = Result.fromThrowable(() => 1 + 1);
|
|
20
|
-
*
|
|
21
|
-
* const failure = Result.fromThrowable(() => {
|
|
22
|
-
* throw new Error('boom');
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* assert.deepStrictEqual(success, Result.ok(2));
|
|
26
|
-
*
|
|
27
|
-
* assert.isTrue(Result.isErr(failure));
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @template T The return type of the function.
|
|
31
|
-
* @param fn The function to execute that may throw.
|
|
32
|
-
* @returns A `Result<T, Error>` containing either the successful result or
|
|
33
|
-
* the caught error.
|
|
34
|
-
*/
|
|
35
6
|
const fromThrowable = (fn) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return err(error);
|
|
42
|
-
}
|
|
43
|
-
const msg = unknownToString(error);
|
|
44
|
-
return err(new Error(msg));
|
|
7
|
+
try {
|
|
8
|
+
return ok(fn());
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (isError(error)) {
|
|
11
|
+
return err(error);
|
|
45
12
|
}
|
|
13
|
+
const msg = unknownToString(error);
|
|
14
|
+
return err(new Error(msg));
|
|
15
|
+
}
|
|
46
16
|
};
|
|
47
17
|
|
|
48
18
|
export { fromThrowable };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-from-throwable.mjs","sources":["../../../../src/functional/result/impl/result-from-throwable.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-from-throwable.mjs","sources":["../../../../src/functional/result/impl/result-from-throwable.mts"],"sourcesContent":["import { isError } from '@sindresorhus/is';\nimport { unknownToString } from '../../../others/index.mjs';\nimport { type Result } from '../result.mjs';\nimport { err } from './result-err.mjs';\nimport { ok } from './result-ok.mjs';\n\n/**\n * Wraps a function that may throw an exception in a `Result`.\n *\n * This is a fundamental utility for converting traditional exception-based\n * error handling into Result-based error handling. Any thrown value is\n * converted to an Error object for consistent error handling.\n *\n * If the function executes successfully, returns `Result.Ok` with the result.\n * If the function throws, returns `Result.Err` with the caught error.\n *\n * @example\n *\n * ```ts\n * const success = Result.fromThrowable(() => 1 + 1);\n *\n * const failure = Result.fromThrowable(() => {\n * throw new Error('boom');\n * });\n *\n * assert.deepStrictEqual(success, Result.ok(2));\n *\n * assert.isTrue(Result.isErr(failure));\n * ```\n *\n * @template T The return type of the function.\n * @param fn The function to execute that may throw.\n * @returns A `Result<T, Error>` containing either the successful result or\n * the caught error.\n */\nexport const fromThrowable = <T,>(fn: () => T): Result<T, Error> => {\n try {\n return ok(fn());\n } catch (error) {\n if (isError(error)) {\n return err(error);\n }\n\n const msg = unknownToString(error);\n\n return err(new Error(msg));\n }\n};\n"],"names":[],"mappings":";;;;;AAmCO,MAAM,aAAA,GAAgB,CAAK,EAAA,KAAkC;AAClE,EAAA,IAAI;AACF,IAAA,OAAO,EAAA,CAAG,IAAI,CAAA;AAAA,EAChB,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,OAAA,CAAQ,KAAK,CAAA,EAAG;AAClB,MAAA,OAAO,IAAI,KAAK,CAAA;AAAA,IAClB;AAEA,IAAA,MAAM,GAAA,GAAM,gBAAgB,KAAK,CAAA;AAEjC,IAAA,OAAO,GAAA,CAAI,IAAI,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAC3B;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-is-err.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"result-is-err.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,aAAa,UACnC,CAAC,KACR,MAAM,IAAI,WAAW,CAAC,CAAC,CAAoC,CAAC"}
|
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
import { ErrTypeTagName } from './tag.mjs';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Type guard for the error variant.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* const operation = Result.ok(3);
|
|
10
|
-
*
|
|
11
|
-
* const failure = Result.err('error');
|
|
12
|
-
*
|
|
13
|
-
* if (Result.isOk(operation)) {
|
|
14
|
-
* const value: number = operation.value;
|
|
15
|
-
*
|
|
16
|
-
* assert.isTrue(value === 3);
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* assert.isTrue(Result.isErr(failure));
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
3
|
const isErr = (result) => result.$$tag === ErrTypeTagName;
|
|
23
4
|
|
|
24
5
|
export { isErr };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-is-err.mjs","sources":["../../../../src/functional/result/impl/result-is-err.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-is-err.mjs","sources":["../../../../src/functional/result/impl/result-is-err.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { ErrTypeTagName } from './tag.mjs';\nimport { type NarrowToErr } from './types.mjs';\n\n/**\n * Type guard for the error variant.\n *\n * @example\n *\n * ```ts\n * const operation = Result.ok(3);\n *\n * const failure = Result.err('error');\n *\n * if (Result.isOk(operation)) {\n * const value: number = operation.value;\n *\n * assert.isTrue(value === 3);\n * }\n *\n * assert.isTrue(Result.isErr(failure));\n * ```\n */\nexport const isErr = <R extends UnknownResult>(\n result: R,\n): result is NarrowToErr<R> => result.$$tag === ErrTypeTagName;\n"],"names":[],"mappings":";;AAuBO,MAAM,KAAA,GAAQ,CACnB,MAAA,KAC6B,MAAA,CAAO,KAAA,KAAU;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-is-ok.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-ok.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"result-is-ok.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-ok.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,aAAa,UAClC,CAAC,KACR,MAAM,IAAI,UAAU,CAAC,CAAC,CAAmC,CAAC"}
|
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
import { OkTypeTagName } from './tag.mjs';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Type guard for the ok variant.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* const operation = Result.ok(3);
|
|
10
|
-
*
|
|
11
|
-
* const failure = Result.err('error');
|
|
12
|
-
*
|
|
13
|
-
* if (Result.isOk(operation)) {
|
|
14
|
-
* const value: number = operation.value;
|
|
15
|
-
*
|
|
16
|
-
* assert.isTrue(value === 3);
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* assert.isTrue(Result.isErr(failure));
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
3
|
const isOk = (result) => result.$$tag === OkTypeTagName;
|
|
23
4
|
|
|
24
5
|
export { isOk };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-is-ok.mjs","sources":["../../../../src/functional/result/impl/result-is-ok.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-is-ok.mjs","sources":["../../../../src/functional/result/impl/result-is-ok.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { OkTypeTagName } from './tag.mjs';\nimport { type NarrowToOk } from './types.mjs';\n\n/**\n * Type guard for the ok variant.\n *\n * @example\n *\n * ```ts\n * const operation = Result.ok(3);\n *\n * const failure = Result.err('error');\n *\n * if (Result.isOk(operation)) {\n * const value: number = operation.value;\n *\n * assert.isTrue(value === 3);\n * }\n *\n * assert.isTrue(Result.isErr(failure));\n * ```\n */\nexport const isOk = <R extends UnknownResult>(\n result: R,\n): result is NarrowToOk<R> => result.$$tag === OkTypeTagName;\n"],"names":[],"mappings":";;AAuBO,MAAM,IAAA,GAAO,CAClB,MAAA,KAC4B,MAAA,CAAO,KAAA,KAAU;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-is-result.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-result.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"result-is-result.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-result.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ,gBAAiB,OAAO,KAAG,WAAW,IAAI,aAIgB,CAAC"}
|
|
@@ -2,29 +2,7 @@ import { hasKey } from '../../../guard/has-key.mjs';
|
|
|
2
2
|
import { isRecord } from '../../../guard/is-record.mjs';
|
|
3
3
|
import { ErrTypeTagName, OkTypeTagName } from './tag.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Checks whether the provided value is a {@link Result<S, E>}.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const okValue = Result.ok('success');
|
|
12
|
-
*
|
|
13
|
-
* const errValue = Result.err(new Error('failure'));
|
|
14
|
-
*
|
|
15
|
-
* const notResult = { $$tag: 'ts-data-forge::Result.ok' } as const;
|
|
16
|
-
*
|
|
17
|
-
* assert.isTrue(Result.isResult(okValue));
|
|
18
|
-
*
|
|
19
|
-
* assert.isTrue(Result.isResult(errValue));
|
|
20
|
-
*
|
|
21
|
-
* assert.isFalse(Result.isResult(notResult));
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
const isResult = (maybeResult) => isRecord(maybeResult) &&
|
|
25
|
-
hasKey(maybeResult, '$$tag') &&
|
|
26
|
-
hasKey(maybeResult, 'value') &&
|
|
27
|
-
(maybeResult.$$tag === ErrTypeTagName || maybeResult.$$tag === OkTypeTagName);
|
|
5
|
+
const isResult = (maybeResult) => isRecord(maybeResult) && hasKey(maybeResult, "$$tag") && hasKey(maybeResult, "value") && (maybeResult.$$tag === ErrTypeTagName || maybeResult.$$tag === OkTypeTagName);
|
|
28
6
|
|
|
29
7
|
export { isResult };
|
|
30
8
|
//# sourceMappingURL=result-is-result.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-is-result.mjs","sources":["../../../../src/functional/result/impl/result-is-result.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-is-result.mjs","sources":["../../../../src/functional/result/impl/result-is-result.mts"],"sourcesContent":["import { hasKey, isRecord } from '../../../guard/index.mjs';\nimport { type UnknownResult } from '../result.mjs';\nimport { ErrTypeTagName, OkTypeTagName } from './tag.mjs';\n\n/**\n * Checks whether the provided value is a {@link Result<S, E>}.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok('success');\n *\n * const errValue = Result.err(new Error('failure'));\n *\n * const notResult = { $$tag: 'ts-data-forge::Result.ok' } as const;\n *\n * assert.isTrue(Result.isResult(okValue));\n *\n * assert.isTrue(Result.isResult(errValue));\n *\n * assert.isFalse(Result.isResult(notResult));\n * ```\n */\nexport const isResult = (maybeResult: unknown): maybeResult is UnknownResult =>\n isRecord(maybeResult) &&\n hasKey(maybeResult, '$$tag') &&\n hasKey(maybeResult, 'value') &&\n (maybeResult.$$tag === ErrTypeTagName || maybeResult.$$tag === OkTypeTagName);\n"],"names":[],"mappings":";;;;AAuBO,MAAM,WAAW,CAAC,WAAA,KACvB,SAAS,WAAW,CAAA,IACpB,OAAO,WAAA,EAAa,OAAO,CAAA,IAC3B,MAAA,CAAO,aAAa,OAAO,CAAA,KAC1B,YAAY,KAAA,KAAU,cAAA,IAAkB,YAAY,KAAA,KAAU,aAAA;;;;"}
|
|
@@ -2,24 +2,24 @@ import { err } from './result-err.mjs';
|
|
|
2
2
|
import { isOk } from './result-is-ok.mjs';
|
|
3
3
|
|
|
4
4
|
function mapErr(...args) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return mapErrImpl(result, mapFn);
|
|
10
|
-
}
|
|
11
|
-
case 1: {
|
|
12
|
-
// Curried version: first argument is mapping function
|
|
13
|
-
const [mapFn] = args;
|
|
14
|
-
return (result) => mapErrImpl(result, mapFn);
|
|
15
|
-
}
|
|
5
|
+
switch (args.length) {
|
|
6
|
+
case 2: {
|
|
7
|
+
const [result, mapFn] = args;
|
|
8
|
+
return mapErrImpl(result, mapFn);
|
|
16
9
|
}
|
|
10
|
+
case 1: {
|
|
11
|
+
const [mapFn] = args;
|
|
12
|
+
return (result) => mapErrImpl(result, mapFn);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
17
15
|
}
|
|
18
|
-
const mapErrImpl = (result, mapFn) => isOk(result)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const mapErrImpl = (result, mapFn) => isOk(result) ? (
|
|
17
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
18
|
+
result
|
|
19
|
+
) : (
|
|
20
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
21
|
+
err(mapFn(result.value))
|
|
22
|
+
);
|
|
23
23
|
|
|
24
24
|
export { mapErr };
|
|
25
25
|
//# sourceMappingURL=result-map-err.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-map-err.mjs","sources":["../../../../src/functional/result/impl/result-map-err.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-map-err.mjs","sources":["../../../../src/functional/result/impl/result-map-err.mts"],"sourcesContent":["import { type Ok } from '../../../types.mjs';\nimport { type Result, type UnknownResult } from '../result.mjs';\nimport { err } from './result-err.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Maps a `Result<S, E>` to `Result<S, E2>` by applying a function to the\n * error value. If the `Result` is `Result.Ok`, returns the original `Ok`.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok(3) as Result<number, string>;\n *\n * const errValue = Result.err('missing');\n *\n * const untouchedOk = Result.mapErr(okValue, (error) => error.toUpperCase());\n *\n * const uppercasedErr = Result.mapErr(errValue, (error) =>\n * error.toUpperCase(),\n * );\n *\n * assert.deepStrictEqual(untouchedOk, Result.ok(3));\n *\n * assert.deepStrictEqual(uppercasedErr, Result.err('MISSING'));\n *\n * const mapError = Result.mapErr((error: Readonly<Error>) => error.message);\n *\n * const wrapped = mapError(Result.err(new Error('boom')));\n *\n * assert.deepStrictEqual(wrapped, Result.err('boom'));\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @template E2 The type of the error value returned by the mapping function.\n * @param result The `Result` to map.\n * @param mapFn The function to apply to the error value if present.\n * @returns A new `Result<UnwrapOk<R>, E2>`.\n */\nexport function mapErr<R extends UnknownResult, E2>(\n result: R,\n mapFn: (error: UnwrapErr<R>) => E2,\n): Result<UnwrapOk<R>, E2>;\n\n// Curried version\nexport function mapErr<E, E2>(\n mapFn: (error: E) => E2,\n): <S>(result: Result<S, E>) => Result<S, E2>;\n\nexport function mapErr<R extends UnknownResult, E2>(\n ...args:\n | readonly [result: R, mapFn: (error: UnwrapErr<R>) => E2]\n | readonly [mapFn: (error: UnwrapErr<R>) => E2]\n): Result<UnwrapOk<R>, E2> | ((result: R) => Result<UnwrapOk<R>, E2>) {\n switch (args.length) {\n case 2: {\n // Direct version: first argument is result\n const [result, mapFn] = args;\n\n return mapErrImpl(result, mapFn);\n }\n\n case 1: {\n // Curried version: first argument is mapping function\n const [mapFn] = args;\n\n return (result: R) => mapErrImpl(result, mapFn);\n }\n }\n}\n\nconst mapErrImpl = <R extends UnknownResult, E2>(\n result: R,\n mapFn: (error: UnwrapErr<R>) => E2,\n): Result<UnwrapOk<R>, E2> =>\n isOk(result)\n ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (result as Ok<UnwrapOk<R>>)\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n err(mapFn(result.value as UnwrapErr<R>));\n"],"names":[],"mappings":";;;AAkDO,SAAS,UACX,IAAA,EAGiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AAExB,MAAA,OAAO,UAAA,CAAW,QAAQ,KAAK,CAAA;AAAA,IACjC;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,KAAK,CAAA,GAAI,IAAA;AAEhB,MAAA,OAAO,CAAC,MAAA,KAAc,UAAA,CAAW,MAAA,EAAQ,KAAK,CAAA;AAAA,IAChD;AAAA;AAEJ;AAEA,MAAM,UAAA,GAAa,CACjB,MAAA,EACA,KAAA,KAEA,KAAK,MAAM,CAAA;AAAA;AAAA,EAEN;AAAA;AAAA;AAAA,EAED,GAAA,CAAI,KAAA,CAAM,MAAA,CAAO,KAAqB,CAAC;AAAA,CAAA;;;;"}
|
|
@@ -2,24 +2,24 @@ import { isErr } from './result-is-err.mjs';
|
|
|
2
2
|
import { ok } from './result-ok.mjs';
|
|
3
3
|
|
|
4
4
|
function map(...args) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return mapImpl(result, mapFn);
|
|
10
|
-
}
|
|
11
|
-
case 1: {
|
|
12
|
-
// Curried version
|
|
13
|
-
const [mapFn] = args;
|
|
14
|
-
return (result) => mapImpl(result, mapFn);
|
|
15
|
-
}
|
|
5
|
+
switch (args.length) {
|
|
6
|
+
case 2: {
|
|
7
|
+
const [result, mapFn] = args;
|
|
8
|
+
return mapImpl(result, mapFn);
|
|
16
9
|
}
|
|
10
|
+
case 1: {
|
|
11
|
+
const [mapFn] = args;
|
|
12
|
+
return (result) => mapImpl(result, mapFn);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
17
15
|
}
|
|
18
|
-
const mapImpl = (result, mapFn) => isErr(result)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const mapImpl = (result, mapFn) => isErr(result) ? (
|
|
17
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
18
|
+
result
|
|
19
|
+
) : (
|
|
20
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
21
|
+
ok(mapFn(result.value))
|
|
22
|
+
);
|
|
23
23
|
|
|
24
24
|
export { map };
|
|
25
25
|
//# sourceMappingURL=result-map.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-map.mjs","sources":["../../../../src/functional/result/impl/result-map.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-map.mjs","sources":["../../../../src/functional/result/impl/result-map.mts"],"sourcesContent":["import { type Err } from '../../../types.mjs';\nimport { type Result, type UnknownResult } from '../result.mjs';\nimport { isErr } from './result-is-err.mjs';\nimport { ok } from './result-ok.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Maps a `Result<S, E>` to `Result<S2, E>` by applying a function to the\n * success value. If the `Result` is `Result.Err`, returns the original\n * `Err`.\n *\n * @example\n *\n * ```ts\n * const okNumber = Result.ok(5);\n *\n * const errMessage = Result.err('error');\n *\n * const doubled = Result.map(okNumber, (value) => value * 2);\n *\n * const untouchedError = Result.map(errMessage, (value: number) => value * 2);\n *\n * assert.deepStrictEqual(doubled, Result.ok(10));\n *\n * assert.deepStrictEqual(untouchedError, errMessage);\n *\n * const mapToLength = Result.map((text: string) => text.length);\n *\n * assert.deepStrictEqual(mapToLength(Result.ok('abc')), Result.ok(3));\n *\n * assert.deepStrictEqual(mapToLength(Result.err('bad')), Result.err('bad'));\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @template S2 The type of the success value returned by the mapping\n * function.\n * @param result The `Result` to map.\n * @param mapFn The function to apply to the success value if present.\n * @returns A new `Result<S2, UnwrapErr<R>>`.\n */\nexport function map<R extends UnknownResult, S2>(\n result: R,\n mapFn: (value: UnwrapOk<R>) => S2,\n): Result<S2, UnwrapErr<R>>;\n\n// Curried version\nexport function map<S, S2>(\n mapFn: (value: S) => S2,\n): <E>(result: Result<S, E>) => Result<S2, E>;\n\nexport function map<R extends UnknownResult, S2>(\n ...args:\n | readonly [result: R, mapFn: (value: UnwrapOk<R>) => S2]\n | readonly [mapFn: (value: UnwrapOk<R>) => S2]\n): Result<S2, UnwrapErr<R>> | ((result: R) => Result<S2, UnwrapErr<R>>) {\n switch (args.length) {\n case 2: {\n // Direct version: first argument is result\n const [result, mapFn] = args;\n\n return mapImpl(result, mapFn);\n }\n\n case 1: {\n // Curried version\n const [mapFn] = args;\n\n return (result: R) => mapImpl(result, mapFn);\n }\n }\n}\n\nconst mapImpl = <R extends UnknownResult, S2>(\n result: R,\n mapFn: (value: UnwrapOk<R>) => S2,\n): Result<S2, UnwrapErr<R>> =>\n isErr(result)\n ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (result as Err<UnwrapErr<R>>)\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n ok(mapFn(result.value as UnwrapOk<R>));\n"],"names":[],"mappings":";;;AAkDO,SAAS,OACX,IAAA,EAGmE;AACtE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AAExB,MAAA,OAAO,OAAA,CAAQ,QAAQ,KAAK,CAAA;AAAA,IAC9B;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,KAAK,CAAA,GAAI,IAAA;AAEhB,MAAA,OAAO,CAAC,MAAA,KAAc,OAAA,CAAQ,MAAA,EAAQ,KAAK,CAAA;AAAA,IAC7C;AAAA;AAEJ;AAEA,MAAM,OAAA,GAAU,CACd,MAAA,EACA,KAAA,KAEA,MAAM,MAAM,CAAA;AAAA;AAAA,EAEP;AAAA;AAAA;AAAA,EAED,EAAA,CAAG,KAAA,CAAM,MAAA,CAAO,KAAoB,CAAC;AAAA,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-ok.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-ok.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAG7C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,EAAE,GAAI,KAAK,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"result-ok.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-ok.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAG7C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,EAAE,GAAI,KAAK,CAAC,CAAC,SAAU,CAAC,KAAG,EAAE,CAAC,CAAC,CAI/B,CAAC"}
|
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
import { OkTypeTagName } from './tag.mjs';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Creates a `Result.Ok` containing the given success value.
|
|
5
|
-
*
|
|
6
|
-
* Use this constructor when an operation succeeds and you want to wrap the
|
|
7
|
-
* successful result in a Result type for consistent error handling.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const success = Result.ok({ id: 1 });
|
|
13
|
-
*
|
|
14
|
-
* const failure = Result.err(new Error('missing data'));
|
|
15
|
-
*
|
|
16
|
-
* assert.deepStrictEqual(success, {
|
|
17
|
-
* $$tag: 'ts-data-forge::Result.ok',
|
|
18
|
-
* value: { id: 1 },
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* assert.isTrue(Result.isErr(failure));
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @template S The type of the success value.
|
|
25
|
-
* @param value The success value.
|
|
26
|
-
* @returns A `Result.Ok<S>` containing the value.
|
|
27
|
-
*/
|
|
28
3
|
const ok = (value) => ({
|
|
29
|
-
|
|
30
|
-
|
|
4
|
+
$$tag: OkTypeTagName,
|
|
5
|
+
value
|
|
31
6
|
});
|
|
32
7
|
|
|
33
8
|
export { ok };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-ok.mjs","sources":["../../../../src/functional/result/impl/result-ok.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-ok.mjs","sources":["../../../../src/functional/result/impl/result-ok.mts"],"sourcesContent":["import { type Ok } from '../../../types.mjs';\nimport { OkTypeTagName } from './tag.mjs';\n\n/**\n * Creates a `Result.Ok` containing the given success value.\n *\n * Use this constructor when an operation succeeds and you want to wrap the\n * successful result in a Result type for consistent error handling.\n *\n * @example\n *\n * ```ts\n * const success = Result.ok({ id: 1 });\n *\n * const failure = Result.err(new Error('missing data'));\n *\n * assert.deepStrictEqual(success, {\n * $$tag: 'ts-data-forge::Result.ok',\n * value: { id: 1 },\n * });\n *\n * assert.isTrue(Result.isErr(failure));\n * ```\n *\n * @template S The type of the success value.\n * @param value The success value.\n * @returns A `Result.Ok<S>` containing the value.\n */\nexport const ok = <const S,>(value: S): Ok<S> =>\n ({\n $$tag: OkTypeTagName,\n value,\n }) as const;\n"],"names":[],"mappings":";;AA4BO,MAAM,EAAA,GAAK,CAAW,KAAA,MAC1B;AAAA,EACC,KAAA,EAAO,aAAA;AAAA,EACP;AACF,CAAA;;;;"}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { isOk } from './result-is-ok.mjs';
|
|
2
2
|
|
|
3
3
|
function orElse(...args) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return orElseImpl(result, alternative);
|
|
9
|
-
}
|
|
10
|
-
case 1: {
|
|
11
|
-
// Curried version
|
|
12
|
-
const [alternative] = args;
|
|
13
|
-
return (result) => orElseImpl(result, alternative);
|
|
14
|
-
}
|
|
4
|
+
switch (args.length) {
|
|
5
|
+
case 2: {
|
|
6
|
+
const [result, alternative] = args;
|
|
7
|
+
return orElseImpl(result, alternative);
|
|
15
8
|
}
|
|
9
|
+
case 1: {
|
|
10
|
+
const [alternative] = args;
|
|
11
|
+
return (result) => orElseImpl(result, alternative);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
16
14
|
}
|
|
17
|
-
const orElseImpl = (result, alternative) =>
|
|
15
|
+
const orElseImpl = (result, alternative) => isOk(result) ? result : alternative;
|
|
18
16
|
|
|
19
17
|
export { orElse };
|
|
20
18
|
//# sourceMappingURL=result-or-else.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-or-else.mjs","sources":["../../../../src/functional/result/impl/result-or-else.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-or-else.mjs","sources":["../../../../src/functional/result/impl/result-or-else.mts"],"sourcesContent":["import { type UnknownResult } from '../result.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { type NarrowToOk } from './types.mjs';\n\n/**\n * Returns the `Result` if it is `Ok`, otherwise returns the alternative.\n *\n * @example\n *\n * ```ts\n * const primary = Result.ok('primary');\n *\n * const fallback = Result.ok('fallback');\n *\n * const failure = Result.err('failure');\n *\n * assert.deepStrictEqual(Result.orElse(primary, fallback), primary);\n *\n * assert.deepStrictEqual(Result.orElse(failure, fallback), fallback);\n *\n * const orElseFallback = Result.orElse(Result.ok('default'));\n *\n * assert.deepStrictEqual(\n * orElseFallback(Result.err('missing')),\n * Result.ok('default'),\n * );\n *\n * assert.deepStrictEqual(\n * orElseFallback(Result.ok('value')),\n * Result.ok('value'),\n * );\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @param result The `Result` to check.\n * @param alternative The alternative `Result` to return if the first is\n * `Err`.\n * @returns The first `Result` if `Ok`, otherwise the alternative.\n */\nexport function orElse<R extends UnknownResult, R2 extends UnknownResult>(\n result: R,\n alternative: R2,\n): NarrowToOk<R> | R2;\n\n// Curried version\nexport function orElse<R2 extends UnknownResult>(\n alternative: R2,\n): <R extends UnknownResult>(result: R) => NarrowToOk<R> | R2;\n\nexport function orElse<R extends UnknownResult, R2 extends UnknownResult>(\n ...args: readonly [result: R, alternative: R2] | readonly [alternative: R2]\n): (NarrowToOk<R> | R2) | ((result: R) => R | R2) {\n switch (args.length) {\n case 2: {\n // Direct version: first argument is result\n const [result, alternative] = args;\n\n return orElseImpl(result, alternative);\n }\n\n case 1: {\n // Curried version\n const [alternative] = args;\n\n return (result: R) => orElseImpl(result, alternative);\n }\n }\n}\n\nconst orElseImpl = <R extends UnknownResult, R2 extends UnknownResult>(\n result: R,\n alternative: R2,\n): NarrowToOk<R> | R2 => (isOk(result) ? result : alternative);\n"],"names":[],"mappings":";;AAiDO,SAAS,UACX,IAAA,EAC6C;AAChD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,MAAA,EAAQ,WAAW,CAAA,GAAI,IAAA;AAE9B,MAAA,OAAO,UAAA,CAAW,QAAQ,WAAW,CAAA;AAAA,IACvC;AAAA,IAEA,KAAK,CAAA,EAAG;AAEN,MAAA,MAAM,CAAC,WAAW,CAAA,GAAI,IAAA;AAEtB,MAAA,OAAO,CAAC,MAAA,KAAc,UAAA,CAAW,MAAA,EAAQ,WAAW,CAAA;AAAA,IACtD;AAAA;AAEJ;AAEA,MAAM,aAAa,CACjB,MAAA,EACA,gBACwB,IAAA,CAAK,MAAM,IAAI,MAAA,GAAS,WAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-swap.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-swap.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAKhE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"result-swap.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-swap.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAKhE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,aAAa,UAClC,CAAC,KACR,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAEsC,CAAC"}
|
|
@@ -3,28 +3,10 @@ import { isOk } from './result-is-ok.mjs';
|
|
|
3
3
|
import { ok } from './result-ok.mjs';
|
|
4
4
|
import { unwrapOk } from './result-unwrap-ok.mjs';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const okValue = Result.ok('value');
|
|
13
|
-
*
|
|
14
|
-
* const errValue = Result.err('error');
|
|
15
|
-
*
|
|
16
|
-
* assert.deepStrictEqual(Result.swap(okValue), Result.err('value'));
|
|
17
|
-
*
|
|
18
|
-
* assert.deepStrictEqual(Result.swap(errValue), Result.ok('error'));
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @template R The input `UnknownResult` type.
|
|
22
|
-
* @param result The `Result` to swap.
|
|
23
|
-
* @returns A new `Result` with success and error swapped.
|
|
24
|
-
*/
|
|
25
|
-
const swap = (result) =>
|
|
26
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
27
|
-
isOk(result) ? err(unwrapOk(result)) : ok(result.value);
|
|
6
|
+
const swap = (result) => (
|
|
7
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
8
|
+
isOk(result) ? err(unwrapOk(result)) : ok(result.value)
|
|
9
|
+
);
|
|
28
10
|
|
|
29
11
|
export { swap };
|
|
30
12
|
//# sourceMappingURL=result-swap.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-swap.mjs","sources":["../../../../src/functional/result/impl/result-swap.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-swap.mjs","sources":["../../../../src/functional/result/impl/result-swap.mts"],"sourcesContent":["import { type Result, type UnknownResult } from '../result.mjs';\nimport { err } from './result-err.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { ok } from './result-ok.mjs';\nimport { unwrapOk } from './result-unwrap-ok.mjs';\nimport { type UnwrapErr, type UnwrapOk } from './types.mjs';\n\n/**\n * Swaps the success and error values of a `Result`.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok('value');\n *\n * const errValue = Result.err('error');\n *\n * assert.deepStrictEqual(Result.swap(okValue), Result.err('value'));\n *\n * assert.deepStrictEqual(Result.swap(errValue), Result.ok('error'));\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @param result The `Result` to swap.\n * @returns A new `Result` with success and error swapped.\n */\nexport const swap = <R extends UnknownResult>(\n result: R,\n): Result<UnwrapErr<R>, UnwrapOk<R>> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n isOk(result) ? err(unwrapOk(result)) : ok(result.value as UnwrapErr<R>);\n"],"names":[],"mappings":";;;;;AA0BO,MAAM,OAAO,CAClB,MAAA;AAAA;AAAA,EAGA,IAAA,CAAK,MAAM,CAAA,GAAI,GAAA,CAAI,QAAA,CAAS,MAAM,CAAC,CAAA,GAAI,EAAA,CAAG,MAAA,CAAO,KAAqB;AAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-to-optional.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-to-optional.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,aAAa,
|
|
1
|
+
{"version":3,"file":"result-to-optional.d.mts","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-to-optional.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,aAAa,UACxC,CAAC,KACR,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CACyC,CAAC"}
|
|
@@ -3,33 +3,6 @@ import { some } from '../../optional/impl/optional-some.mjs';
|
|
|
3
3
|
import { isOk } from './result-is-ok.mjs';
|
|
4
4
|
import { unwrapOk } from './result-unwrap-ok.mjs';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Converts a `Result` to an `Optional`.
|
|
8
|
-
*
|
|
9
|
-
* This conversion is useful when you want to discard error information and
|
|
10
|
-
* only care about whether an operation succeeded. The error information is
|
|
11
|
-
* lost in this conversion, so use it when error details are not needed.
|
|
12
|
-
*
|
|
13
|
-
* If the `Result` is `Ok`, returns `Some` with the value. If the `Result` is
|
|
14
|
-
* `Err`, returns `None`.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* const okValue = Result.ok(7);
|
|
20
|
-
*
|
|
21
|
-
* const errValue = Result.err('fail');
|
|
22
|
-
*
|
|
23
|
-
* assert.deepStrictEqual(Result.toOptional(okValue), Optional.some(7));
|
|
24
|
-
*
|
|
25
|
-
* assert.deepStrictEqual(Result.toOptional(errValue), Optional.none);
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @template R The input `UnknownResult` type.
|
|
29
|
-
* @param result The `Result` to convert.
|
|
30
|
-
* @returns An `Optional<UnwrapOk<R>>` containing the success value or
|
|
31
|
-
* representing `None`.
|
|
32
|
-
*/
|
|
33
6
|
const toOptional = (result) => isOk(result) ? some(unwrapOk(result)) : none;
|
|
34
7
|
|
|
35
8
|
export { toOptional };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-to-optional.mjs","sources":["../../../../src/functional/result/impl/result-to-optional.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"result-to-optional.mjs","sources":["../../../../src/functional/result/impl/result-to-optional.mts"],"sourcesContent":["import { Optional } from '../../optional/index.mjs';\nimport { type UnknownResult } from '../result.mjs';\nimport { isOk } from './result-is-ok.mjs';\nimport { unwrapOk } from './result-unwrap-ok.mjs';\nimport { type UnwrapOk } from './types.mjs';\n\n/**\n * Converts a `Result` to an `Optional`.\n *\n * This conversion is useful when you want to discard error information and\n * only care about whether an operation succeeded. The error information is\n * lost in this conversion, so use it when error details are not needed.\n *\n * If the `Result` is `Ok`, returns `Some` with the value. If the `Result` is\n * `Err`, returns `None`.\n *\n * @example\n *\n * ```ts\n * const okValue = Result.ok(7);\n *\n * const errValue = Result.err('fail');\n *\n * assert.deepStrictEqual(Result.toOptional(okValue), Optional.some(7));\n *\n * assert.deepStrictEqual(Result.toOptional(errValue), Optional.none);\n * ```\n *\n * @template R The input `UnknownResult` type.\n * @param result The `Result` to convert.\n * @returns An `Optional<UnwrapOk<R>>` containing the success value or\n * representing `None`.\n */\nexport const toOptional = <R extends UnknownResult>(\n result: R,\n): Optional<UnwrapOk<R>> =>\n isOk(result) ? Optional.some(unwrapOk(result)) : Optional.none;\n"],"names":["Optional.some","Optional.none"],"mappings":";;;;;AAiCO,MAAM,UAAA,GAAa,CACxB,MAAA,KAEA,IAAA,CAAK,MAAM,CAAA,GAAIA,IAAS,CAAK,QAAA,CAAS,MAAM,CAAC,CAAA,GAAIC;;;;"}
|