ts-data-forge 14.6.0 → 14.6.2
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/dist/array/impl/array-utils-creation.mjs +126 -26
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +63 -30
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.mjs +69 -53
- package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +109 -73
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +71 -33
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +102 -73
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +77 -33
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs +75 -122
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +100 -150
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +110 -134
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +146 -38
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +10 -8
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs +13 -50
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +94 -78
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +291 -199
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +54 -56
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/array/impl/index.mjs +17 -17
- package/dist/array/impl/index.mjs.map +1 -1
- package/dist/array/index.mjs +2 -3
- package/dist/array/index.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs +335 -291
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.mjs +280 -239
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/index.mjs +7 -7
- package/dist/collections/index.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +448 -263
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.mjs +328 -201
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.mjs +183 -151
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.mjs +169 -140
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +4 -77
- package/dist/entry-point.mjs.map +1 -1
- package/dist/expect-type.mjs +70 -4
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/async-result/async-result.mjs +2 -3
- package/dist/functional/async-result/async-result.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-flat-map.mjs +19 -21
- package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-from-promise.mjs +9 -10
- package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs +12 -14
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-map-err.mjs +16 -19
- package/dist/functional/async-result/impl/async-result-map-err.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-map.mjs +16 -19
- package/dist/functional/async-result/impl/async-result-map.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +36 -9
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +1 -1
- package/dist/functional/async-result/impl/index.mjs +8 -7
- package/dist/functional/async-result/impl/index.mjs.map +1 -1
- package/dist/functional/async-result/impl/types.mjs +2 -2
- package/dist/functional/async-result/impl/types.mjs.map +1 -1
- package/dist/functional/async-result/index.mjs +2 -3
- package/dist/functional/async-result/index.mjs.map +1 -1
- package/dist/functional/index.mjs +7 -11
- package/dist/functional/index.mjs.map +1 -1
- package/dist/functional/match.mjs +27 -13
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional/impl/index.mjs +19 -18
- package/dist/functional/optional/impl/index.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs +16 -18
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-filter.mjs +17 -19
- package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs +13 -15
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +26 -5
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +21 -5
- package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +26 -8
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +22 -5
- package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-map.mjs +16 -18
- package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-match.mjs +16 -18
- package/dist/functional/optional/impl/optional-match.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +18 -5
- package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.mjs +13 -15
- package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +23 -7
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +28 -5
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs +12 -14
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +34 -9
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs +6 -9
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +36 -5
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/optional/impl/tag.mjs +4 -5
- package/dist/functional/optional/impl/tag.mjs.map +1 -1
- package/dist/functional/optional/impl/types.mjs +2 -2
- package/dist/functional/optional/impl/types.mjs.map +1 -1
- package/dist/functional/optional/index.mjs +2 -3
- package/dist/functional/optional/index.mjs.map +1 -1
- package/dist/functional/optional/optional.mjs +2 -3
- package/dist/functional/optional/optional.mjs.map +1 -1
- package/dist/functional/pipe.mjs +42 -14
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result/impl/index.mjs +28 -27
- package/dist/functional/result/impl/index.mjs.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +29 -7
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs +17 -18
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.mjs +18 -21
- package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-fold.mjs +18 -21
- package/dist/functional/result/impl/result-fold.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-optional.mjs +17 -20
- package/dist/functional/result/impl/result-from-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +37 -8
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +41 -14
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +21 -5
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +21 -5
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +25 -7
- package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
- package/dist/functional/result/impl/result-map-err.mjs +18 -21
- package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-map.mjs +18 -21
- package/dist/functional/result/impl/result-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-match.mjs +17 -21
- package/dist/functional/result/impl/result-match.mjs.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +29 -7
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-or-else.mjs +14 -15
- package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
- package/dist/functional/result/impl/result-safe-try.mjs +32 -21
- package/dist/functional/result/impl/result-safe-try.mjs.map +1 -1
- package/dist/functional/result/impl/result-safe-unwrap.mjs +40 -12
- package/dist/functional/result/impl/result-safe-unwrap.mjs.map +1 -1
- package/dist/functional/result/impl/result-swap.mjs +23 -8
- package/dist/functional/result/impl/result-swap.mjs.map +1 -1
- package/dist/functional/result/impl/result-to-optional.mjs +30 -7
- package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs +13 -14
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +43 -20
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +33 -8
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs +13 -14
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs +6 -9
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +38 -11
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-zip.mjs +35 -5
- package/dist/functional/result/impl/result-zip.mjs.map +1 -1
- package/dist/functional/result/impl/tag.mjs +4 -5
- package/dist/functional/result/impl/tag.mjs.map +1 -1
- package/dist/functional/result/impl/types.mjs +2 -2
- package/dist/functional/result/impl/types.mjs.map +1 -1
- package/dist/functional/result/index.mjs +2 -3
- package/dist/functional/result/index.mjs.map +1 -1
- package/dist/functional/result/result.mjs +2 -3
- package/dist/functional/result/result.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/index.mjs +29 -28
- package/dist/functional/ternary-result/impl/index.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/tag.mjs +6 -6
- package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +17 -7
- 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 +15 -18
- 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 +28 -32
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +24 -26
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +21 -8
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +28 -13
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +19 -5
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +21 -5
- 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.mjs +28 -8
- 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.mjs +20 -5
- 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 +17 -18
- 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 +20 -23
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +24 -26
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +18 -7
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +11 -14
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +24 -10
- 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 +11 -14
- 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.mjs +30 -19
- 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.mjs +20 -8
- 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 +11 -14
- 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 +7 -9
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +30 -22
- 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 +11 -14
- 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.mjs +27 -17
- 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.mjs +20 -8
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +21 -8
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +47 -19
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/types.mjs +2 -2
- package/dist/functional/ternary-result/impl/types.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/variant-name.mjs +12 -14
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
- package/dist/functional/ternary-result/index.mjs +2 -3
- package/dist/functional/ternary-result/index.mjs.map +1 -1
- package/dist/functional/ternary-result/ternary-result.mjs +2 -3
- package/dist/functional/ternary-result/ternary-result.mjs.map +1 -1
- package/dist/guard/has-key.mjs +43 -4
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/index.mjs +8 -8
- package/dist/guard/index.mjs.map +1 -1
- package/dist/guard/is-non-empty-string.mjs +39 -4
- package/dist/guard/is-non-empty-string.mjs.map +1 -1
- package/dist/guard/is-non-null-object.mjs +36 -4
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-primitive.mjs +46 -15
- package/dist/guard/is-primitive.mjs.map +1 -1
- package/dist/guard/is-record.mjs +89 -6
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.mjs +404 -19
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.mjs +42 -4
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +12 -65
- package/dist/index.mjs.map +1 -1
- package/dist/iterator/index.mjs +2 -2
- package/dist/iterator/index.mjs.map +1 -1
- package/dist/iterator/range.mjs +19 -57
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/index.mjs +2 -2
- package/dist/json/index.mjs.map +1 -1
- package/dist/json/json.mjs +346 -105
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +148 -137
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/index.mjs +33 -33
- package/dist/number/branded-types/index.mjs.map +1 -1
- package/dist/number/branded-types/int.mjs +245 -209
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.mjs +141 -131
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.mjs +141 -131
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +155 -149
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +125 -110
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +126 -115
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +164 -154
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +137 -125
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +137 -125
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +143 -139
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +116 -99
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +118 -107
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +144 -129
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +102 -82
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +118 -105
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +118 -105
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +122 -108
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +118 -104
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +118 -104
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +167 -160
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +260 -224
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +134 -122
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +134 -122
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +292 -258
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +134 -122
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +134 -122
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +284 -255
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +135 -124
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.mjs +248 -211
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.mjs +132 -121
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.mjs +132 -121
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/index.mjs +3 -3
- package/dist/number/enum/index.mjs.map +1 -1
- package/dist/number/enum/int8.mjs +146 -131
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.mjs +133 -119
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/index.mjs +6 -37
- package/dist/number/index.mjs.map +1 -1
- package/dist/number/num-arithmetic-types.mjs +42 -1
- package/dist/number/num-arithmetic-types.mjs.map +1 -1
- package/dist/number/num.mjs +541 -83
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.mjs +294 -133
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/index.mjs +2 -2
- package/dist/object/index.mjs.map +1 -1
- package/dist/object/object.mjs +355 -202
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/cast-mutable.mjs +38 -11
- package/dist/others/cast-mutable.mjs.map +1 -1
- package/dist/others/cast-readonly.mjs +37 -11
- package/dist/others/cast-readonly.mjs.map +1 -1
- package/dist/others/debounce-function.mjs +22 -11
- package/dist/others/debounce-function.mjs.map +1 -1
- package/dist/others/fast-deep-equal.mjs +70 -51
- package/dist/others/fast-deep-equal.mjs.map +1 -1
- package/dist/others/if-then.mjs +32 -5
- package/dist/others/if-then.mjs.map +1 -1
- package/dist/others/index.mjs +10 -10
- package/dist/others/index.mjs.map +1 -1
- package/dist/others/map-nullable.mjs +11 -13
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/memoize-function.mjs +14 -16
- package/dist/others/memoize-function.mjs.map +1 -1
- package/dist/others/tuple.mjs +52 -4
- package/dist/others/tuple.mjs.map +1 -1
- package/dist/others/unknown-to-string.mjs +91 -47
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/index.mjs +2 -2
- package/dist/promise/index.mjs.map +1 -1
- package/dist/promise/promise.mjs +51 -10
- package/dist/promise/promise.mjs.map +1 -1
- package/dist/string/index.mjs +2 -2
- package/dist/string/index.mjs.map +1 -1
- package/dist/string/str.mjs +250 -83
- package/dist/string/str.mjs.map +1 -1
- package/dist/types.mjs +3 -2
- package/dist/types.mjs.map +1 -1
- package/package.json +5 -6
- package/src/array/impl/array-utils-length-constraint-preservation.test.mts +2 -2
- package/src/collections/imap-mapped.mts +4 -4
- package/src/collections/imap.mts +1 -1
- package/src/collections/imap.test.mts +1 -1
- package/src/collections/iset-mapped.mts +2 -1
- package/src/collections/iset.mts +1 -1
- package/src/functional/async-result.test.mts +3 -2
- package/src/functional/optional.test.mts +2 -1
- package/src/functional/result.test.mts +0 -2
- package/src/guard/is-non-empty-string.test.mts +2 -2
- package/src/guard/is-non-null-object.test.mts +3 -3
- package/src/guard/is-primitive.test.mts +3 -3
- package/src/guard/is-type.test.mts +3 -3
- package/src/json/json.test.mts +1 -1
- package/src/number/enum/int8.mts +1 -1
|
@@ -1,19 +1,46 @@
|
|
|
1
1
|
import { isError } from '@sindresorhus/is';
|
|
2
|
-
import { unknownToString } from '../../../others/
|
|
2
|
+
import { unknownToString } from '../../../others/index.mjs';
|
|
3
3
|
import { err } from './result-err.mjs';
|
|
4
4
|
import { ok } from './result-ok.mjs';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Wraps a function that may throw an exception in a `Result`.
|
|
7
|
+
*
|
|
8
|
+
* This is a fundamental utility for converting traditional exception-based
|
|
9
|
+
* error handling into Result-based error handling. Any thrown value is
|
|
10
|
+
* converted to an Error object for consistent error handling.
|
|
11
|
+
*
|
|
12
|
+
* If the function executes successfully, returns `Result.Ok` with the result.
|
|
13
|
+
* If the function throws, returns `Result.Err` with the caught error.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const success = Result.fromThrowable(() => 1 + 1);
|
|
19
|
+
*
|
|
20
|
+
* const failure = Result.fromThrowable(() => {
|
|
21
|
+
* throw new Error('boom');
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* assert.deepStrictEqual(success, Result.ok(2));
|
|
25
|
+
*
|
|
26
|
+
* assert.isTrue(Result.isErr(failure));
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @template T The return type of the function.
|
|
30
|
+
* @param fn The function to execute that may throw.
|
|
31
|
+
* @returns A `Result<T, Error>` containing either the successful result or
|
|
32
|
+
* the caught error.
|
|
33
|
+
*/
|
|
34
|
+
export const fromThrowable = (fn) => {
|
|
35
|
+
try {
|
|
36
|
+
return ok(fn());
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (isError(error)) {
|
|
40
|
+
return err(error);
|
|
41
|
+
}
|
|
42
|
+
const msg = unknownToString(error);
|
|
43
|
+
return err(new Error(msg));
|
|
12
44
|
}
|
|
13
|
-
const msg = unknownToString(error);
|
|
14
|
-
return err(new Error(msg));
|
|
15
|
-
}
|
|
16
45
|
};
|
|
17
|
-
|
|
18
|
-
export { fromThrowable };
|
|
19
|
-
//# sourceMappingURL=result-from-throwable.mjs.map
|
|
46
|
+
//# sourceMappingURL=result-from-throwable.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-from-throwable.mjs","sources":["../../../../src/functional/result/impl/result-from-throwable.mts"],"
|
|
1
|
+
{"version":3,"file":"result-from-throwable.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-from-throwable.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAK,EAAW,EAAoB,EAAE;IACjE,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACnB,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;QAED,MAAM,GAAG,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAEnC,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { ErrTypeTagName } from './tag.mjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for the error variant.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const operation = Result.ok(3);
|
|
9
|
+
*
|
|
10
|
+
* const failure = Result.err('error');
|
|
11
|
+
*
|
|
12
|
+
* if (Result.isOk(operation)) {
|
|
13
|
+
* const value: number = operation.value;
|
|
14
|
+
*
|
|
15
|
+
* assert.isTrue(value === 3);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* assert.isTrue(Result.isErr(failure));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const isErr = (result) => result.$$tag === ErrTypeTagName;
|
|
22
|
+
//# sourceMappingURL=result-is-err.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-is-err.mjs","sources":["../../../../src/functional/result/impl/result-is-err.mts"],"
|
|
1
|
+
{"version":3,"file":"result-is-err.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-err.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,MAAS,EACiB,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,cAAc,CAAC"}
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { OkTypeTagName } from './tag.mjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for the ok variant.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const operation = Result.ok(3);
|
|
9
|
+
*
|
|
10
|
+
* const failure = Result.err('error');
|
|
11
|
+
*
|
|
12
|
+
* if (Result.isOk(operation)) {
|
|
13
|
+
* const value: number = operation.value;
|
|
14
|
+
*
|
|
15
|
+
* assert.isTrue(value === 3);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* assert.isTrue(Result.isErr(failure));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const isOk = (result) => result.$$tag === OkTypeTagName;
|
|
22
|
+
//# sourceMappingURL=result-is-ok.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-is-ok.mjs","sources":["../../../../src/functional/result/impl/result-is-ok.mts"],"
|
|
1
|
+
{"version":3,"file":"result-is-ok.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-ok.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,MAAS,EACgB,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,aAAa,CAAC"}
|
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import { hasKey } from '../../../guard/
|
|
2
|
-
import { isRecord } from '../../../guard/is-record.mjs';
|
|
1
|
+
import { hasKey, isRecord } from '../../../guard/index.mjs';
|
|
3
2
|
import { ErrTypeTagName, OkTypeTagName } from './tag.mjs';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Checks whether the provided value is a {@link Result<S, E>}.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const okValue = Result.ok('success');
|
|
10
|
+
*
|
|
11
|
+
* const errValue = Result.err(new Error('failure'));
|
|
12
|
+
*
|
|
13
|
+
* const notResult = { $$tag: 'ts-data-forge::Result.ok' } as const;
|
|
14
|
+
*
|
|
15
|
+
* assert.isTrue(Result.isResult(okValue));
|
|
16
|
+
*
|
|
17
|
+
* assert.isTrue(Result.isResult(errValue));
|
|
18
|
+
*
|
|
19
|
+
* assert.isFalse(Result.isResult(notResult));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const isResult = (maybeResult) => isRecord(maybeResult) &&
|
|
23
|
+
hasKey(maybeResult, '$$tag') &&
|
|
24
|
+
hasKey(maybeResult, 'value') &&
|
|
25
|
+
(maybeResult.$$tag === ErrTypeTagName || maybeResult.$$tag === OkTypeTagName);
|
|
26
|
+
//# 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"],"
|
|
1
|
+
{"version":3,"file":"result-is-result.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-is-result.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,WAAoB,EAAgC,EAAE,CAC7E,QAAQ,CAAC,WAAW,CAAC;IACrB,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC;IAC5B,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC;IAC5B,CAAC,WAAW,CAAC,KAAK,KAAK,cAAc,IAAI,WAAW,CAAC,KAAK,KAAK,aAAa,CAAC,CAAC"}
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import { err } from './result-err.mjs';
|
|
2
2
|
import { isOk } from './result-is-ok.mjs';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export function mapErr(...args) {
|
|
4
|
+
switch (args.length) {
|
|
5
|
+
case 2: {
|
|
6
|
+
// Direct version: first argument is result
|
|
7
|
+
const [result, mapFn] = args;
|
|
8
|
+
return mapErrImpl(result, mapFn);
|
|
9
|
+
}
|
|
10
|
+
case 1: {
|
|
11
|
+
// Curried version: first argument is mapping function
|
|
12
|
+
const [mapFn] = args;
|
|
13
|
+
return (result) => mapErrImpl(result, mapFn);
|
|
14
|
+
}
|
|
9
15
|
}
|
|
10
|
-
case 1: {
|
|
11
|
-
const [mapFn] = args;
|
|
12
|
-
return (result) => mapErrImpl(result, mapFn);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
16
|
}
|
|
16
|
-
const mapErrImpl = (result, mapFn) => isOk(result)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
export { mapErr };
|
|
25
|
-
//# sourceMappingURL=result-map-err.mjs.map
|
|
17
|
+
const mapErrImpl = (result, mapFn) => isOk(result)
|
|
18
|
+
? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
19
|
+
result
|
|
20
|
+
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
21
|
+
err(mapFn(result.value));
|
|
22
|
+
//# 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"],"
|
|
1
|
+
{"version":3,"file":"result-map-err.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-map-err.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AA8D1C,MAAM,UAAU,MAAM,CACpB,GAAG,IAE8C;IAEjD,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,2CAA2C;YAC3C,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;YAE7B,OAAO,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACnC,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,sDAAsD;YACtD,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;YAErB,OAAO,CAAC,MAAS,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,GAAG,CACjB,MAAS,EACT,KAAkC,EACT,EAAE,CAC3B,IAAI,CAAC,MAAM,CAAC;IACV,CAAC,CAAC,oEAAoE;QACnE,MAA0B;IAC7B,CAAC,CAAC,oEAAoE;QACpE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAqB,CAAC,CAAC,CAAC"}
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import { isErr } from './result-is-err.mjs';
|
|
2
2
|
import { ok } from './result-ok.mjs';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export function map(...args) {
|
|
4
|
+
switch (args.length) {
|
|
5
|
+
case 2: {
|
|
6
|
+
// Direct version: first argument is result
|
|
7
|
+
const [result, mapFn] = args;
|
|
8
|
+
return mapImpl(result, mapFn);
|
|
9
|
+
}
|
|
10
|
+
case 1: {
|
|
11
|
+
// Curried version
|
|
12
|
+
const [mapFn] = args;
|
|
13
|
+
return (result) => mapImpl(result, mapFn);
|
|
14
|
+
}
|
|
9
15
|
}
|
|
10
|
-
case 1: {
|
|
11
|
-
const [mapFn] = args;
|
|
12
|
-
return (result) => mapImpl(result, mapFn);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
16
|
}
|
|
16
|
-
const mapImpl = (result, mapFn) => isErr(result)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
export { map };
|
|
25
|
-
//# sourceMappingURL=result-map.mjs.map
|
|
17
|
+
const mapImpl = (result, mapFn) => isErr(result)
|
|
18
|
+
? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
19
|
+
result
|
|
20
|
+
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
21
|
+
ok(mapFn(result.value));
|
|
22
|
+
//# sourceMappingURL=result-map.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-map.mjs","sources":["../../../../src/functional/result/impl/result-map.mts"],"
|
|
1
|
+
{"version":3,"file":"result-map.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-map.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AA8DrC,MAAM,UAAU,GAAG,CACjB,GAAG,IAE6C;IAEhD,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,2CAA2C;YAC3C,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;YAE7B,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,kBAAkB;YAClB,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;YAErB,OAAO,CAAC,MAAS,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,OAAO,GAAG,CACd,MAAS,EACT,KAAiC,EACP,EAAE,CAC5B,KAAK,CAAC,MAAM,CAAC;IACX,CAAC,CAAC,oEAAoE;QACnE,MAA4B;IAC/B,CAAC,CAAC,oEAAoE;QACpE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAoB,CAAC,CAAC,CAAC"}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { isOk } from './result-is-ok.mjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export function match(...args) {
|
|
3
|
+
switch (args.length) {
|
|
4
|
+
case 2: {
|
|
5
|
+
const [result, cases] = args;
|
|
6
|
+
return matchImpl(result, cases);
|
|
7
|
+
}
|
|
8
|
+
case 1: {
|
|
9
|
+
// Curried version: the only argument is the case handlers
|
|
10
|
+
const [cases] = args;
|
|
11
|
+
return (result) => matchImpl(result, cases);
|
|
12
|
+
}
|
|
8
13
|
}
|
|
9
|
-
case 1: {
|
|
10
|
-
const [cases] = args;
|
|
11
|
-
return (result) => matchImpl(result, cases);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
14
|
}
|
|
15
|
-
const matchImpl = (result, cases) => isOk(result)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
export { match };
|
|
24
|
-
//# sourceMappingURL=result-match.mjs.map
|
|
15
|
+
const matchImpl = (result, cases) => isOk(result)
|
|
16
|
+
? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
17
|
+
cases.ok(result.value)
|
|
18
|
+
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
19
|
+
cases.err(result.value);
|
|
20
|
+
//# sourceMappingURL=result-match.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-match.mjs","sources":["../../../../src/functional/result/impl/result-match.mts"],"
|
|
1
|
+
{"version":3,"file":"result-match.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-match.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AA+D1C,MAAM,UAAU,KAAK,CACnB,GAAG,IAaE;IAEL,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;YAE7B,OAAO,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,0DAA0D;YAC1D,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;YAErB,OAAO,CAAC,MAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,SAAS,GAAG,CAChB,MAAS,EACT,KAGE,EACO,EAAE,CACX,IAAI,CAAC,MAAM,CAAC;IACV,CAAC,CAAC,oEAAoE;QACpE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAoB,CAAC;IACvC,CAAC,CAAC,oEAAoE;QACpE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAqB,CAAC,CAAC"}
|
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import { OkTypeTagName } from './tag.mjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Creates a `Result.Ok` containing the given success value.
|
|
4
|
+
*
|
|
5
|
+
* Use this constructor when an operation succeeds and you want to wrap the
|
|
6
|
+
* successful result in a Result type for consistent error handling.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const success = Result.ok({ id: 1 });
|
|
12
|
+
*
|
|
13
|
+
* const failure = Result.err(new Error('missing data'));
|
|
14
|
+
*
|
|
15
|
+
* assert.deepStrictEqual(success, {
|
|
16
|
+
* $$tag: 'ts-data-forge::Result.ok',
|
|
17
|
+
* value: { id: 1 },
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* assert.isTrue(Result.isErr(failure));
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @template S The type of the success value.
|
|
24
|
+
* @param value The success value.
|
|
25
|
+
* @returns A `Result.Ok<S>` containing the value.
|
|
26
|
+
*/
|
|
27
|
+
export const ok = (value) => ({
|
|
28
|
+
$$tag: OkTypeTagName,
|
|
29
|
+
value,
|
|
6
30
|
});
|
|
7
|
-
|
|
8
|
-
export { ok };
|
|
9
|
-
//# sourceMappingURL=result-ok.mjs.map
|
|
31
|
+
//# sourceMappingURL=result-ok.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-ok.mjs","sources":["../../../../src/functional/result/impl/result-ok.mts"],"
|
|
1
|
+
{"version":3,"file":"result-ok.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-ok.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAAW,KAAQ,EAAS,EAAE,CAC9C,CAAC;IACC,KAAK,EAAE,aAAa;IACpB,KAAK;CACN,CAAU,CAAC"}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { isOk } from './result-is-ok.mjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export function orElse(...args) {
|
|
3
|
+
switch (args.length) {
|
|
4
|
+
case 2: {
|
|
5
|
+
// Direct version: first argument is result
|
|
6
|
+
const [result, alternative] = args;
|
|
7
|
+
return orElseImpl(result, alternative);
|
|
8
|
+
}
|
|
9
|
+
case 1: {
|
|
10
|
+
// Curried version
|
|
11
|
+
const [alternative] = args;
|
|
12
|
+
return (result) => orElseImpl(result, alternative);
|
|
13
|
+
}
|
|
8
14
|
}
|
|
9
|
-
case 1: {
|
|
10
|
-
const [alternative] = args;
|
|
11
|
-
return (result) => orElseImpl(result, alternative);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
15
|
}
|
|
15
|
-
const orElseImpl = (result, alternative) => isOk(result) ? result : alternative;
|
|
16
|
-
|
|
17
|
-
export { orElse };
|
|
18
|
-
//# sourceMappingURL=result-or-else.mjs.map
|
|
16
|
+
const orElseImpl = (result, alternative) => (isOk(result) ? result : alternative);
|
|
17
|
+
//# 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"],"
|
|
1
|
+
{"version":3,"file":"result-or-else.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-or-else.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAgD1C,MAAM,UAAU,MAAM,CACpB,GAAG,IAAwE;IAE3E,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,2CAA2C;YAC3C,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAI,CAAC;YAEnC,OAAO,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACzC,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,kBAAkB;YAClB,MAAM,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;YAE3B,OAAO,CAAC,MAAS,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,GAAG,CACjB,MAAS,EACT,WAAe,EACK,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC"}
|
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
import { hasKey } from '../../../guard/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
1
|
+
import { hasKey, isRecord } from '../../../guard/index.mjs';
|
|
2
|
+
export function safeTry(body) {
|
|
3
|
+
const generator = body();
|
|
4
|
+
// A yielded `Err` and a returned `Result` are both already the final
|
|
5
|
+
// answer, so the first step's `value` is the result in either case: the
|
|
6
|
+
// generator is closed rather than resumed after yielding.
|
|
7
|
+
const step = generator.next();
|
|
8
|
+
if (isSyncStep(step)) {
|
|
9
|
+
// Dropping a suspended generator would skip the `finally` blocks and
|
|
10
|
+
// `using` disposals still pending in the body; closing it runs them
|
|
11
|
+
// before the short-circuited `Err` is handed back. `isSyncGenerator` is
|
|
12
|
+
// what makes `return()` here synchronous rather than a floating promise.
|
|
13
|
+
if (step.done !== true && isSyncGenerator(generator, step)) {
|
|
14
|
+
generator.return(step.value);
|
|
15
|
+
}
|
|
16
|
+
return step.value;
|
|
10
17
|
}
|
|
11
|
-
return step.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return asyncStep.value;
|
|
18
|
-
});
|
|
18
|
+
return step.then(async (asyncStep) => {
|
|
19
|
+
if (asyncStep.done !== true) {
|
|
20
|
+
await generator.return(asyncStep.value);
|
|
21
|
+
}
|
|
22
|
+
return asyncStep.value;
|
|
23
|
+
});
|
|
19
24
|
}
|
|
20
|
-
|
|
25
|
+
// A sync generator's `next()` returns a plain `{ value, done }` object with
|
|
26
|
+
// own properties, while an async generator's returns a `Promise`, whose
|
|
27
|
+
// `then` lives on the prototype — so an own-key check on `done` separates the
|
|
28
|
+
// two.
|
|
29
|
+
const isSyncStep = (value) => isRecord(value) && hasKey(value, 'done');
|
|
30
|
+
// The generator-side counterpart of `isSyncStep`: a step in the sync form can
|
|
31
|
+
// only have come from a sync generator, so the step is what narrows the
|
|
32
|
+
// generator that produced it — hence the predicate reads its second argument
|
|
33
|
+
// and not its first.
|
|
21
34
|
const isSyncGenerator = (_generator, step) => isSyncStep(step);
|
|
22
|
-
|
|
23
|
-
export { safeTry };
|
|
24
|
-
//# sourceMappingURL=result-safe-try.mjs.map
|
|
35
|
+
//# sourceMappingURL=result-safe-try.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-safe-try.mjs","sources":["../../../../src/functional/result/impl/result-safe-try.mts"],"
|
|
1
|
+
{"version":3,"file":"result-safe-try.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-safe-try.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AA0D5D,MAAM,UAAU,OAAO,CACrB,IAEmD;IAEnD,MAAM,SAAS,GAAG,IAAI,EAAE,CAAC;IAEzB,qEAAqE;IACrE,wEAAwE;IACxE,0DAA0D;IAC1D,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;IAE9B,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,qEAAqE;QACrE,oEAAoE;QACpE,wEAAwE;QACxE,yEAAyE;QACzE,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC;YAC3D,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACnC,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAC5B,MAAM,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;QAED,OAAO,SAAS,CAAC,KAAK,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,4EAA4E;AAC5E,wEAAwE;AACxE,8EAA8E;AAC9E,OAAO;AACP,MAAM,UAAU,GAAG,CACjB,KAAc,EACyC,EAAE,CACzD,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAE3C,8EAA8E;AAC9E,wEAAwE;AACxE,6EAA6E;AAC7E,qBAAqB;AACrB,MAAM,eAAe,GAAG,CACtB,UAE2C,EAC3C,IAAa,EAC0C,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1,14 +1,42 @@
|
|
|
1
1
|
import { isErr } from './result-is-err.mjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Unwraps a `Result` inside a {@link Result.safeTry} generator body via
|
|
4
|
+
* `yield*`, emulating Rust's `?` operator.
|
|
5
|
+
*
|
|
6
|
+
* If the `Result` is `Ok`, the `yield*` expression evaluates to the contained
|
|
7
|
+
* value and execution continues. If it is `Err`, the error is yielded to
|
|
8
|
+
* {@link Result.safeTry}, which returns it immediately — the rest of the
|
|
9
|
+
* generator body never runs.
|
|
10
|
+
*
|
|
11
|
+
* This generator must only be delegated to (`yield*`) inside a
|
|
12
|
+
* {@link Result.safeTry} body; resuming it after it has yielded an `Err`
|
|
13
|
+
* throws.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const result = Result.safeTry(function* () {
|
|
19
|
+
* const x = yield* Result.safeUnwrap(Result.ok(2));
|
|
20
|
+
*
|
|
21
|
+
* const y = yield* Result.safeUnwrap(Result.ok(3));
|
|
22
|
+
*
|
|
23
|
+
* return Result.ok(x + y);
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* assert.deepStrictEqual(result, Result.ok(5));
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @template R The input `UnknownResult` type.
|
|
30
|
+
* @param result The `Result` to unwrap.
|
|
31
|
+
* @returns A generator that yields the `Err` (if any) and returns the `Ok`
|
|
32
|
+
* value.
|
|
33
|
+
*/
|
|
34
|
+
export function* safeUnwrap(result) {
|
|
35
|
+
if (isErr(result)) {
|
|
36
|
+
yield result;
|
|
37
|
+
throw new Error('`safeUnwrap()` generator was resumed after yielding an `Err`; it must only be used via `yield*` inside `safeTry()`');
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
40
|
+
return result.value;
|
|
11
41
|
}
|
|
12
|
-
|
|
13
|
-
export { safeUnwrap };
|
|
14
|
-
//# sourceMappingURL=result-safe-unwrap.mjs.map
|
|
42
|
+
//# sourceMappingURL=result-safe-unwrap.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-safe-unwrap.mjs","sources":["../../../../src/functional/result/impl/result-safe-unwrap.mts"],"
|
|
1
|
+
{"version":3,"file":"result-safe-unwrap.mjs","sourceRoot":"","sources":["../../../../src/functional/result/impl/result-safe-unwrap.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,SAAS,CAAC,CAAC,UAAU,CACzB,MAAS;IAET,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAClB,MAAM,MAAM,CAAC;QAEb,MAAM,IAAI,KAAK,CACb,oHAAoH,CACrH,CAAC;IACJ,CAAC;IAED,oEAAoE;IACpE,OAAO,MAAM,CAAC,KAAoB,CAAC;AACrC,CAAC"}
|