ts-data-forge 5.0.1 → 5.1.1
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 +101 -50
- package/dist/array/impl/array-utils-creation.d.mts +14 -0
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs +12 -0
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +10 -0
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +6 -0
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +14 -0
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +34 -10
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +34 -4
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +20 -7
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +20 -7
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +5 -2
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +5 -2
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts +2 -0
- package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +17 -2
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +9 -2
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +27 -0
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +6 -0
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +35 -18
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +25 -14
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +35 -15
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +5 -3
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +46 -19
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +9 -2
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +48 -19
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +9 -2
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +65 -25
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +13 -5
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +60 -25
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +12 -5
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -1
- package/dist/functional/match.d.mts +1 -1
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +3 -2
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-filter.d.mts +3 -0
- package/dist/functional/optional/impl/optional-filter.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +2 -0
- package/dist/functional/optional/impl/optional-flat-map.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts +2 -0
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +2 -0
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +4 -2
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +4 -2
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +2 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +2 -1
- package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-map.d.mts +2 -0
- package/dist/functional/optional/impl/optional-map.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-none.d.mts +4 -2
- package/dist/functional/optional/impl/optional-none.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +4 -2
- package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.d.mts +4 -0
- package/dist/functional/optional/impl/optional-or-else.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.d.mts +5 -3
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +4 -2
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +7 -4
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +4 -2
- package/dist/functional/optional/impl/optional-unwrap.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +3 -1
- package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +3 -1
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +2 -2
- package/dist/functional/result/impl/result-err.d.mts +4 -2
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +3 -1
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +3 -2
- package/dist/functional/result/impl/result-expect-to-be.d.mts.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +5 -0
- package/dist/functional/result/impl/result-flat-map.d.mts.map +1 -1
- package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-fold.d.mts +4 -0
- package/dist/functional/result/impl/result-fold.d.mts.map +1 -1
- package/dist/functional/result/impl/result-fold.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-promise.d.mts +4 -1
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +4 -1
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +3 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +3 -1
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +4 -2
- package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +4 -2
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +4 -2
- package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +4 -2
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts +7 -3
- package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +7 -3
- package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
- package/dist/functional/result/impl/result-map-err.d.mts +3 -0
- package/dist/functional/result/impl/result-map-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-map.d.mts +4 -0
- package/dist/functional/result/impl/result-map.d.mts.map +1 -1
- package/dist/functional/result/impl/result-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-ok.d.mts +4 -2
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +3 -1
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-or-else.d.mts +4 -0
- package/dist/functional/result/impl/result-or-else.d.mts.map +1 -1
- package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
- package/dist/functional/result/impl/result-swap.d.mts +2 -0
- package/dist/functional/result/impl/result-swap.d.mts.map +1 -1
- package/dist/functional/result/impl/result-swap.mjs +2 -0
- package/dist/functional/result/impl/result-swap.mjs.map +1 -1
- package/dist/functional/result/impl/result-to-optional.d.mts +2 -0
- package/dist/functional/result/impl/result-to-optional.d.mts.map +1 -1
- package/dist/functional/result/impl/result-to-optional.mjs +2 -0
- package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +7 -4
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +3 -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 +3 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +3 -2
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +3 -2
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +7 -4
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +3 -2
- package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +3 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +3 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-zip.d.mts +3 -1
- package/dist/functional/result/impl/result-zip.d.mts.map +1 -1
- package/dist/functional/result/impl/result-zip.mjs +3 -1
- package/dist/functional/result/impl/result-zip.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +3 -2
- 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 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +1 -1
- 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.d.mts +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +1 -1
- 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 +3 -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 +3 -1
- 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 +3 -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 +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +1 -0
- 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 +1 -0
- 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 +7 -3
- 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 +7 -3
- 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 +1 -0
- 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 +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +3 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +3 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +6 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +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.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +1 -1
- 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 +2 -0
- 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 +2 -0
- 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.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +1 -1
- 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 +1 -0
- 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 +1 -0
- 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 +2 -0
- 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 +2 -0
- 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.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +1 -1
- 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.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +1 -1
- 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 +1 -0
- 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 +1 -0
- 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.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +1 -1
- 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 +1 -0
- 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 +1 -0
- 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 +2 -0
- 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 +2 -0
- 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 +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.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
- package/dist/globals.d.mts +12 -1
- package/dist/guard/has-key.d.mts +6 -3
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +2 -2
- package/dist/guard/index.mjs +1 -1
- package/dist/guard/is-record.d.mts +31 -0
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +32 -1
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.d.mts +3 -0
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/guard/is-type.mjs +3 -0
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +3 -2
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +3 -2
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/iterator/range.d.mts +4 -0
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs +1 -0
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +42 -21
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +42 -21
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +33 -19
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +33 -19
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +2 -2
- package/dist/number/branded-types/positive-int.d.mts +34 -20
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +34 -20
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +47 -26
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +48 -27
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +48 -27
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +50 -29
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +1 -1
- package/dist/number/branded-types/uint.d.mts +31 -19
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +31 -19
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/num.d.mts +29 -20
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +24 -17
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +33 -11
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +33 -11
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +12 -3
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +10 -3
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/tuple.d.mts +14 -3
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +14 -3
- 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.map +1 -1
- package/dist/promise/promise.d.mts +8 -4
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +8 -4
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +26 -28
- package/src/array/impl/array-utils-creation.mts +20 -0
- package/src/array/impl/array-utils-creation.test.mts +72 -1
- package/src/array/impl/array-utils-element-access.mts +13 -0
- package/src/array/impl/array-utils-element-access.test.mts +36 -15
- package/src/array/impl/array-utils-iterators.test.mts +17 -0
- package/src/array/impl/array-utils-modification.mts +78 -19
- package/src/array/impl/array-utils-modification.test.mts +75 -0
- package/src/array/impl/array-utils-overload-type-error.test.mts +19 -0
- package/src/array/impl/array-utils-reducing-value.mts +61 -16
- package/src/array/impl/array-utils-reducing-value.test.mts +107 -25
- package/src/array/impl/array-utils-search.mts +57 -4
- package/src/array/impl/array-utils-search.test.mts +61 -10
- package/src/array/impl/array-utils-set-op.mts +26 -7
- package/src/array/impl/array-utils-set-op.test.mts +129 -13
- package/src/array/impl/array-utils-size.mts +5 -2
- package/src/array/impl/array-utils-size.test.mts +1 -0
- package/src/array/impl/array-utils-slice-clamped.mts +7 -0
- package/src/array/impl/array-utils-slice-clamped.test.mts +20 -0
- package/src/array/impl/array-utils-slicing.mts +29 -2
- package/src/array/impl/array-utils-slicing.test.mts +57 -0
- package/src/array/impl/array-utils-transformation.mts +58 -0
- package/src/array/impl/array-utils-transformation.test.mts +115 -3
- package/src/array/impl/array-utils-validation.mts +41 -18
- package/src/array/impl/array-utils-validation.test.mts +176 -78
- package/src/array/impl/array.test.mts +18 -6
- package/src/collections/imap-mapped.mts +11 -0
- package/src/collections/imap-mapped.test.mts +86 -18
- package/src/collections/imap.mts +47 -15
- package/src/collections/imap.test.mts +137 -31
- package/src/collections/iset-mapped.mts +54 -19
- package/src/collections/iset-mapped.test.mts +163 -52
- package/src/collections/iset.mts +53 -19
- package/src/collections/iset.test.mts +323 -130
- package/src/collections/queue.mts +78 -25
- package/src/collections/queue.test.mts +65 -35
- package/src/collections/stack.mts +67 -25
- package/src/collections/stack.test.mts +59 -15
- package/src/functional/match.mts +17 -1
- package/src/functional/match.test.mts +2 -0
- package/src/functional/optional/impl/optional-expect-to-be.mts +5 -2
- package/src/functional/optional/impl/optional-filter.mts +6 -0
- package/src/functional/optional/impl/optional-flat-map.mts +4 -0
- package/src/functional/optional/impl/optional-from-nullable.mts +2 -0
- package/src/functional/optional/impl/optional-is-none.mts +1 -1
- package/src/functional/optional/impl/optional-is-optional.mts +4 -2
- package/src/functional/optional/impl/optional-is-some.mts +2 -1
- package/src/functional/optional/impl/optional-map.mts +5 -0
- package/src/functional/optional/impl/optional-none.mts +4 -2
- package/src/functional/optional/impl/optional-or-else.mts +6 -0
- package/src/functional/optional/impl/optional-some.mts +5 -3
- package/src/functional/optional/impl/optional-to-nullable.mts +4 -2
- package/src/functional/optional/impl/optional-unwrap-or.mts +9 -4
- package/src/functional/optional/impl/optional-unwrap-throw.mts +2 -1
- package/src/functional/optional/impl/optional-unwrap.mts +4 -2
- package/src/functional/optional/impl/optional-zip.mts +3 -1
- package/src/functional/optional.test.mts +126 -54
- package/src/functional/pipe.mts +2 -2
- package/src/functional/pipe.test.mts +7 -4
- package/src/functional/result/impl/result-err.mts +4 -2
- package/src/functional/result/impl/result-expect-to-be.mts +5 -2
- package/src/functional/result/impl/result-flat-map.mts +7 -0
- package/src/functional/result/impl/result-fold.mts +6 -0
- package/src/functional/result/impl/result-from-promise.mts +4 -1
- package/src/functional/result/impl/result-from-throwable.mts +5 -1
- package/src/functional/result/impl/result-is-err.mts +4 -2
- package/src/functional/result/impl/result-is-ok.mts +4 -2
- package/src/functional/result/impl/result-is-result.mts +7 -3
- package/src/functional/result/impl/result-map-err.mts +5 -0
- package/src/functional/result/impl/result-map.mts +6 -0
- package/src/functional/result/impl/result-ok.mts +4 -2
- package/src/functional/result/impl/result-or-else.mts +6 -0
- package/src/functional/result/impl/result-swap.mts +2 -0
- package/src/functional/result/impl/result-to-optional.mts +2 -0
- package/src/functional/result/impl/result-unwrap-err-or.mts +9 -4
- package/src/functional/result/impl/result-unwrap-err-throw.mts +3 -1
- package/src/functional/result/impl/result-unwrap-err.mts +3 -2
- package/src/functional/result/impl/result-unwrap-ok-or.mts +9 -4
- package/src/functional/result/impl/result-unwrap-ok.mts +4 -2
- package/src/functional/result/impl/result-unwrap-throw.mts +3 -1
- package/src/functional/result/impl/result-zip.mts +3 -1
- package/src/functional/result.test.mts +182 -152
- package/src/functional/ternary-result/impl/ternary-result-err.mts +3 -2
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +4 -0
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +7 -0
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +3 -1
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +4 -1
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +7 -3
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +6 -0
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +6 -0
- package/src/functional/ternary-result/impl/ternary-result-map.mts +9 -0
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +3 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +4 -1
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +4 -0
- package/src/functional/ternary-result.test.mts +99 -8
- package/src/globals.d.mts +12 -1
- package/src/guard/has-key.mts +8 -5
- package/src/guard/has-key.test.mts +9 -5
- package/src/guard/is-error.test.mts +143 -0
- package/src/guard/is-non-empty-string.test.mts +44 -24
- package/src/guard/is-non-null-object.test.mts +45 -26
- package/src/guard/is-primitive.test.mts +51 -28
- package/src/guard/is-record.mts +34 -0
- package/src/guard/is-record.test.mts +28 -7
- package/src/guard/is-type.mts +3 -0
- package/src/guard/is-type.test.mts +285 -155
- package/src/guard/key-is-in.mts +3 -2
- package/src/guard/key-is-in.test.mts +2 -2
- package/src/iterator/range.mts +9 -0
- package/src/json/json.mts +50 -21
- package/src/json/json.test.mts +224 -176
- package/src/number/branded-types/finite-number.test.mts +51 -11
- package/src/number/branded-types/int.mts +33 -19
- package/src/number/branded-types/int.test.mts +56 -14
- package/src/number/branded-types/int16.test.mts +63 -16
- package/src/number/branded-types/int32.test.mts +63 -16
- package/src/number/branded-types/non-negative-finite-number.test.mts +52 -12
- package/src/number/branded-types/non-negative-int16.test.mts +59 -16
- package/src/number/branded-types/non-negative-int32.test.mts +59 -16
- package/src/number/branded-types/non-zero-finite-number.test.mts +65 -14
- package/src/number/branded-types/non-zero-int.test.mts +72 -19
- package/src/number/branded-types/non-zero-int16.test.mts +60 -16
- package/src/number/branded-types/non-zero-int32.test.mts +60 -16
- package/src/number/branded-types/non-zero-safe-int.mts +2 -2
- package/src/number/branded-types/non-zero-safe-int.test.mts +85 -23
- package/src/number/branded-types/non-zero-uint16.test.mts +53 -16
- package/src/number/branded-types/non-zero-uint32.test.mts +53 -16
- package/src/number/branded-types/positive-finite-number.test.mts +59 -14
- package/src/number/branded-types/positive-int.mts +34 -20
- package/src/number/branded-types/positive-int.test.mts +64 -17
- package/src/number/branded-types/positive-int16.test.mts +50 -15
- package/src/number/branded-types/positive-int32.test.mts +50 -15
- package/src/number/branded-types/positive-safe-int.mts +48 -27
- package/src/number/branded-types/positive-safe-int.test.mts +68 -19
- package/src/number/branded-types/positive-uint16.test.mts +53 -16
- package/src/number/branded-types/positive-uint32.test.mts +53 -16
- package/src/number/branded-types/safe-int.mts +50 -29
- package/src/number/branded-types/safe-int.test.mts +70 -18
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/branded-types/safe-uint.test.mts +65 -17
- package/src/number/branded-types/uint.mts +31 -19
- package/src/number/branded-types/uint.test.mts +58 -15
- package/src/number/branded-types/uint16.test.mts +56 -15
- package/src/number/branded-types/uint32.test.mts +56 -15
- package/src/number/enum/int8.test.mts +7 -1
- package/src/number/enum/uint8.test.mts +7 -1
- package/src/number/num.mts +32 -21
- package/src/number/num.test.mts +88 -26
- package/src/number/refined-number-utils.mts +38 -13
- package/src/object/object.mts +19 -3
- package/src/object/object.test.mts +16 -6
- package/src/others/cast-mutable.test.mts +8 -1
- package/src/others/cast-readonly.test.mts +21 -4
- package/src/others/if-then.test.mts +40 -24
- package/src/others/map-nullable.mts +3 -0
- package/src/others/map-nullable.test.mts +27 -0
- package/src/others/memoize-function.test.mts +41 -0
- package/src/others/tuple.mts +14 -3
- package/src/others/unknown-to-string.mts +2 -0
- package/src/others/unknown-to-string.test.mts +10 -0
- package/src/promise/promise.mts +8 -4
- package/src/promise/promise.test.mts +8 -13
|
@@ -11,12 +11,13 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* const okValue = Result.ok('data');
|
|
13
13
|
*
|
|
14
|
-
* assert(Result.expectToBe(okValue, 'should have value') === 'data');
|
|
14
|
+
* assert.isTrue(Result.expectToBe(okValue, 'should have value') === 'data');
|
|
15
15
|
*
|
|
16
16
|
* const expectResult = Result.expectToBe<string>('missing result');
|
|
17
17
|
*
|
|
18
18
|
* assert.throws(() => expectResult(Result.err('boom')), /missing result/u);
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* assert.isTrue(expectResult(Result.ok('value')) === 'value');
|
|
20
21
|
* ```
|
|
21
22
|
*
|
|
22
23
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -40,12 +41,14 @@ export function expectToBe<R extends UnknownResult>(
|
|
|
40
41
|
case 2: {
|
|
41
42
|
// Direct version: first argument is result
|
|
42
43
|
const [result, message] = args;
|
|
44
|
+
|
|
43
45
|
return expectToBeImpl(result, message);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
case 1: {
|
|
47
49
|
// Curried version: first argument is message
|
|
48
50
|
const [message] = args;
|
|
51
|
+
|
|
49
52
|
return (result: R): UnwrapOk<R> => expectToBeImpl(result, message);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -11,15 +11,20 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* const parseNumber = (input: string): Result<number, string> => {
|
|
13
13
|
* const num = Number.parseInt(input, 10);
|
|
14
|
+
*
|
|
14
15
|
* return Number.isNaN(num) ? Result.err('not a number') : Result.ok(num);
|
|
15
16
|
* };
|
|
16
17
|
*
|
|
17
18
|
* const parsed = Result.flatMap(Result.ok('42'), parseNumber);
|
|
19
|
+
*
|
|
18
20
|
* const failure = Result.flatMap(Result.ok('abc'), parseNumber);
|
|
21
|
+
*
|
|
19
22
|
* const passthrough = Result.flatMap(Result.err('fail'), parseNumber);
|
|
20
23
|
*
|
|
21
24
|
* assert.deepStrictEqual(parsed, Result.ok(42));
|
|
25
|
+
*
|
|
22
26
|
* assert.deepStrictEqual(failure, Result.err('not a number'));
|
|
27
|
+
*
|
|
23
28
|
* assert.deepStrictEqual(passthrough, Result.err('fail'));
|
|
24
29
|
*
|
|
25
30
|
* const parseThenDouble = Result.flatMap((input: string) =>
|
|
@@ -57,12 +62,14 @@ export function flatMap<R extends UnknownResult, S2, E2>(
|
|
|
57
62
|
case 2: {
|
|
58
63
|
// Direct version: first argument is result
|
|
59
64
|
const [result, flatMapFn] = args;
|
|
65
|
+
|
|
60
66
|
return flatMapImpl(result, flatMapFn);
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
case 1: {
|
|
64
70
|
// Curried version
|
|
65
71
|
const [flatMapFn] = args;
|
|
72
|
+
|
|
66
73
|
return (result: R) => flatMapImpl(result, flatMapFn);
|
|
67
74
|
}
|
|
68
75
|
}
|
|
@@ -11,6 +11,7 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const okValue = Result.ok(2);
|
|
14
|
+
*
|
|
14
15
|
* const errValue = Result.err('bad');
|
|
15
16
|
*
|
|
16
17
|
* const foldedOk = Result.fold(
|
|
@@ -18,6 +19,7 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
18
19
|
* (value) => value * 2,
|
|
19
20
|
* (error) => error,
|
|
20
21
|
* );
|
|
22
|
+
*
|
|
21
23
|
* const foldedErr = Result.fold(
|
|
22
24
|
* errValue,
|
|
23
25
|
* (value: number) => value * 2,
|
|
@@ -25,6 +27,7 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
25
27
|
* );
|
|
26
28
|
*
|
|
27
29
|
* assert.deepStrictEqual(foldedOk, Result.ok(4));
|
|
30
|
+
*
|
|
28
31
|
* assert.deepStrictEqual(foldedErr, Result.err('BAD'));
|
|
29
32
|
*
|
|
30
33
|
* const foldNumbers = Result.fold(
|
|
@@ -33,6 +36,7 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
33
36
|
* );
|
|
34
37
|
*
|
|
35
38
|
* assert.deepStrictEqual(foldNumbers(Result.ok(3)), Result.ok(9));
|
|
39
|
+
*
|
|
36
40
|
* assert.deepStrictEqual(foldNumbers(Result.err('oops')), Result.err(4));
|
|
37
41
|
* ```
|
|
38
42
|
*
|
|
@@ -72,12 +76,14 @@ export function fold<R extends UnknownResult, S2, E2>(
|
|
|
72
76
|
case 3: {
|
|
73
77
|
// Direct version: first argument is result
|
|
74
78
|
const [result, mapFn, mapErrFn] = args;
|
|
79
|
+
|
|
75
80
|
return foldImpl(result, mapFn, mapErrFn);
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
case 2: {
|
|
79
84
|
// Curried version
|
|
80
85
|
const [mapFn, mapErrFn] = args;
|
|
86
|
+
|
|
81
87
|
return (result: R) => foldImpl(result, mapFn, mapErrFn);
|
|
82
88
|
}
|
|
83
89
|
}
|
|
@@ -19,13 +19,16 @@ type UnwrapPromise<P extends Promise<unknown>> =
|
|
|
19
19
|
*
|
|
20
20
|
* ```ts
|
|
21
21
|
* const successPromise = Result.fromPromise(Promise.resolve('ok'));
|
|
22
|
+
*
|
|
22
23
|
* const failurePromise = Result.fromPromise(Promise.reject(new Error('fail')));
|
|
23
24
|
*
|
|
24
25
|
* const resolved = await successPromise;
|
|
26
|
+
*
|
|
25
27
|
* const rejected = await failurePromise;
|
|
26
28
|
*
|
|
27
29
|
* assert.deepStrictEqual(resolved, Result.ok('ok'));
|
|
28
|
-
*
|
|
30
|
+
*
|
|
31
|
+
* assert.isTrue(Result.isErr(rejected));
|
|
29
32
|
* ```
|
|
30
33
|
*
|
|
31
34
|
* @template P The type of the input Promise.
|
|
@@ -17,12 +17,14 @@ import { ok } from './result-ok.mjs';
|
|
|
17
17
|
*
|
|
18
18
|
* ```ts
|
|
19
19
|
* const success = Result.fromThrowable(() => 1 + 1);
|
|
20
|
+
*
|
|
20
21
|
* const failure = Result.fromThrowable(() => {
|
|
21
22
|
* throw new Error('boom');
|
|
22
23
|
* });
|
|
23
24
|
*
|
|
24
25
|
* assert.deepStrictEqual(success, Result.ok(2));
|
|
25
|
-
*
|
|
26
|
+
*
|
|
27
|
+
* assert.isTrue(Result.isErr(failure));
|
|
26
28
|
* ```
|
|
27
29
|
*
|
|
28
30
|
* @template T The return type of the function.
|
|
@@ -37,7 +39,9 @@ export const fromThrowable = <T,>(fn: () => T): Result<T, Error> => {
|
|
|
37
39
|
if (isError(error)) {
|
|
38
40
|
return err(error);
|
|
39
41
|
}
|
|
42
|
+
|
|
40
43
|
const msg = unknownToString(error);
|
|
44
|
+
|
|
41
45
|
return err(new Error(msg));
|
|
42
46
|
}
|
|
43
47
|
};
|
|
@@ -8,14 +8,16 @@ import { type NarrowToErr } from './types.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const operation = Result.ok(3);
|
|
11
|
+
*
|
|
11
12
|
* const failure = Result.err('error');
|
|
12
13
|
*
|
|
13
14
|
* if (Result.isOk(operation)) {
|
|
14
15
|
* const value: number = operation.value;
|
|
15
|
-
*
|
|
16
|
+
*
|
|
17
|
+
* assert.isTrue(value === 3);
|
|
16
18
|
* }
|
|
17
19
|
*
|
|
18
|
-
* assert.
|
|
20
|
+
* assert.isTrue(Result.isErr(failure));
|
|
19
21
|
* ```
|
|
20
22
|
*/
|
|
21
23
|
export const isErr = <R extends UnknownResult>(
|
|
@@ -8,14 +8,16 @@ import { type NarrowToOk } from './types.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const operation = Result.ok(3);
|
|
11
|
+
*
|
|
11
12
|
* const failure = Result.err('error');
|
|
12
13
|
*
|
|
13
14
|
* if (Result.isOk(operation)) {
|
|
14
15
|
* const value: number = operation.value;
|
|
15
|
-
*
|
|
16
|
+
*
|
|
17
|
+
* assert.isTrue(value === 3);
|
|
16
18
|
* }
|
|
17
19
|
*
|
|
18
|
-
* assert.
|
|
20
|
+
* assert.isTrue(Result.isErr(failure));
|
|
19
21
|
* ```
|
|
20
22
|
*/
|
|
21
23
|
export const isOk = <R extends UnknownResult>(
|
|
@@ -8,12 +8,16 @@ import { ErrTypeTagName, OkTypeTagName } from './tag.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const okValue = Result.ok('success');
|
|
11
|
+
*
|
|
11
12
|
* const errValue = Result.err(new Error('failure'));
|
|
13
|
+
*
|
|
12
14
|
* const notResult = { $$tag: 'ts-data-forge::Result.ok' };
|
|
13
15
|
*
|
|
14
|
-
* assert.
|
|
15
|
-
*
|
|
16
|
-
* assert.
|
|
16
|
+
* assert.isTrue(Result.isResult(okValue));
|
|
17
|
+
*
|
|
18
|
+
* assert.isTrue(Result.isResult(errValue));
|
|
19
|
+
*
|
|
20
|
+
* assert.isFalse(Result.isResult(notResult));
|
|
17
21
|
* ```
|
|
18
22
|
*/
|
|
19
23
|
export const isResult = (maybeResult: unknown): maybeResult is UnknownResult =>
|
|
@@ -10,12 +10,15 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
10
10
|
*
|
|
11
11
|
* ```ts
|
|
12
12
|
* const okValue = Result.ok(3) as Result<number, string>;
|
|
13
|
+
*
|
|
13
14
|
* const errValue = Result.err('missing');
|
|
14
15
|
*
|
|
15
16
|
* const untouchedOk = Result.mapErr(okValue, (error) => error.toUpperCase());
|
|
17
|
+
*
|
|
16
18
|
* const uppercasedErr = Result.mapErr(errValue, (error) => error.toUpperCase());
|
|
17
19
|
*
|
|
18
20
|
* assert.deepStrictEqual(untouchedOk, Result.ok(3));
|
|
21
|
+
*
|
|
19
22
|
* assert.deepStrictEqual(uppercasedErr, Result.err('MISSING'));
|
|
20
23
|
*
|
|
21
24
|
* const mapError = Result.mapErr((error: Readonly<Error>) => error.message);
|
|
@@ -50,12 +53,14 @@ export function mapErr<R extends UnknownResult, E2>(
|
|
|
50
53
|
case 2: {
|
|
51
54
|
// Direct version: first argument is result
|
|
52
55
|
const [result, mapFn] = args;
|
|
56
|
+
|
|
53
57
|
return mapErrImpl(result, mapFn);
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
case 1: {
|
|
57
61
|
// Curried version: first argument is mapping function
|
|
58
62
|
const [mapFn] = args;
|
|
63
|
+
|
|
59
64
|
return (result: R) => mapErrImpl(result, mapFn);
|
|
60
65
|
}
|
|
61
66
|
}
|
|
@@ -11,17 +11,21 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const okNumber = Result.ok(5);
|
|
14
|
+
*
|
|
14
15
|
* const errMessage = Result.err('error');
|
|
15
16
|
*
|
|
16
17
|
* const doubled = Result.map(okNumber, (value) => value * 2);
|
|
18
|
+
*
|
|
17
19
|
* const untouchedError = Result.map(errMessage, (value: number) => value * 2);
|
|
18
20
|
*
|
|
19
21
|
* assert.deepStrictEqual(doubled, Result.ok(10));
|
|
22
|
+
*
|
|
20
23
|
* assert.deepStrictEqual(untouchedError, errMessage);
|
|
21
24
|
*
|
|
22
25
|
* const mapToLength = Result.map((text: string) => text.length);
|
|
23
26
|
*
|
|
24
27
|
* assert.deepStrictEqual(mapToLength(Result.ok('abc')), Result.ok(3));
|
|
28
|
+
*
|
|
25
29
|
* assert.deepStrictEqual(mapToLength(Result.err('bad')), Result.err('bad'));
|
|
26
30
|
* ```
|
|
27
31
|
*
|
|
@@ -51,12 +55,14 @@ export function map<R extends UnknownResult, S2>(
|
|
|
51
55
|
case 2: {
|
|
52
56
|
// Direct version: first argument is result
|
|
53
57
|
const [result, mapFn] = args;
|
|
58
|
+
|
|
54
59
|
return mapImpl(result, mapFn);
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
case 1: {
|
|
58
63
|
// Curried version
|
|
59
64
|
const [mapFn] = args;
|
|
65
|
+
|
|
60
66
|
return (result: R) => mapImpl(result, mapFn);
|
|
61
67
|
}
|
|
62
68
|
}
|
|
@@ -10,20 +10,22 @@ import { OkTypeTagName } from './tag.mjs';
|
|
|
10
10
|
*
|
|
11
11
|
* ```ts
|
|
12
12
|
* const success = Result.ok({ id: 1 });
|
|
13
|
+
*
|
|
13
14
|
* const failure = Result.err(new Error('missing data'));
|
|
14
15
|
*
|
|
15
16
|
* assert.deepStrictEqual(success, {
|
|
16
17
|
* $$tag: 'ts-data-forge::Result.ok',
|
|
17
18
|
* value: { id: 1 },
|
|
18
19
|
* });
|
|
19
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* assert.isTrue(Result.isErr(failure));
|
|
20
22
|
* ```
|
|
21
23
|
*
|
|
22
24
|
* @template S The type of the success value.
|
|
23
25
|
* @param value The success value.
|
|
24
26
|
* @returns A `Result.Ok<S>` containing the value.
|
|
25
27
|
*/
|
|
26
|
-
export const ok = <S,>(value: S): Ok<S> => ({
|
|
28
|
+
export const ok = <const S,>(value: S): Ok<S> => ({
|
|
27
29
|
$$tag: OkTypeTagName,
|
|
28
30
|
value,
|
|
29
31
|
});
|
|
@@ -8,10 +8,13 @@ import { type NarrowToOk } from './types.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const primary = Result.ok('primary');
|
|
11
|
+
*
|
|
11
12
|
* const fallback = Result.ok('fallback');
|
|
13
|
+
*
|
|
12
14
|
* const failure = Result.err('failure');
|
|
13
15
|
*
|
|
14
16
|
* assert.deepStrictEqual(Result.orElse(primary, fallback), primary);
|
|
17
|
+
*
|
|
15
18
|
* assert.deepStrictEqual(Result.orElse(failure, fallback), fallback);
|
|
16
19
|
*
|
|
17
20
|
* const orElseFallback = Result.orElse(Result.ok('default'));
|
|
@@ -20,6 +23,7 @@ import { type NarrowToOk } from './types.mjs';
|
|
|
20
23
|
* orElseFallback(Result.err('missing')),
|
|
21
24
|
* Result.ok('default'),
|
|
22
25
|
* );
|
|
26
|
+
*
|
|
23
27
|
* assert.deepStrictEqual(orElseFallback(Result.ok('value')), Result.ok('value'));
|
|
24
28
|
* ```
|
|
25
29
|
*
|
|
@@ -46,12 +50,14 @@ export function orElse<R extends UnknownResult, R2 extends UnknownResult>(
|
|
|
46
50
|
case 2: {
|
|
47
51
|
// Direct version: first argument is result
|
|
48
52
|
const [result, alternative] = args;
|
|
53
|
+
|
|
49
54
|
return orElseImpl(result, alternative);
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
case 1: {
|
|
53
58
|
// Curried version
|
|
54
59
|
const [alternative] = args;
|
|
60
|
+
|
|
55
61
|
return (result: R) => orElseImpl(result, alternative);
|
|
56
62
|
}
|
|
57
63
|
}
|
|
@@ -11,9 +11,11 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const okValue = Result.ok('value');
|
|
14
|
+
*
|
|
14
15
|
* const errValue = Result.err('error');
|
|
15
16
|
*
|
|
16
17
|
* assert.deepStrictEqual(Result.swap(okValue), Result.err('value'));
|
|
18
|
+
*
|
|
17
19
|
* assert.deepStrictEqual(Result.swap(errValue), Result.ok('error'));
|
|
18
20
|
* ```
|
|
19
21
|
*
|
|
@@ -17,9 +17,11 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
17
17
|
*
|
|
18
18
|
* ```ts
|
|
19
19
|
* const okValue = Result.ok(7);
|
|
20
|
+
*
|
|
20
21
|
* const errValue = Result.err('fail');
|
|
21
22
|
*
|
|
22
23
|
* assert.deepStrictEqual(Result.toOptional(okValue), Optional.some(7));
|
|
24
|
+
*
|
|
23
25
|
* assert.deepStrictEqual(Result.toOptional(errValue), Optional.none);
|
|
24
26
|
* ```
|
|
25
27
|
*
|
|
@@ -9,15 +9,18 @@ import { type UnwrapErr } from './types.mjs';
|
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
11
|
* const okResult = Result.ok('success');
|
|
12
|
+
*
|
|
12
13
|
* const errResult = Result.err('failure');
|
|
13
14
|
*
|
|
14
|
-
* assert(Result.unwrapErrOr(okResult, 'default') === 'default');
|
|
15
|
-
*
|
|
15
|
+
* assert.isTrue(Result.unwrapErrOr(okResult, 'default') === 'default');
|
|
16
|
+
*
|
|
17
|
+
* assert.isTrue(Result.unwrapErrOr(errResult, 'default') === 'failure');
|
|
16
18
|
*
|
|
17
19
|
* const unwrapError = Result.unwrapErrOr('fallback error');
|
|
18
20
|
*
|
|
19
|
-
* assert(unwrapError(Result.err('boom')) === 'boom');
|
|
20
|
-
*
|
|
21
|
+
* assert.isTrue(unwrapError(Result.err('boom')) === 'boom');
|
|
22
|
+
*
|
|
23
|
+
* assert.isTrue(unwrapError(Result.ok('no error')) === 'fallback error');
|
|
21
24
|
* ```
|
|
22
25
|
*
|
|
23
26
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -43,12 +46,14 @@ export function unwrapErrOr<R extends UnknownResult, D>(
|
|
|
43
46
|
case 2: {
|
|
44
47
|
// Direct version: first argument is result
|
|
45
48
|
const [result, defaultValue] = args;
|
|
49
|
+
|
|
46
50
|
return unwrapErrOrImpl(result, defaultValue);
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
case 1: {
|
|
50
54
|
// Curried version
|
|
51
55
|
const [defaultValue] = args;
|
|
56
|
+
|
|
52
57
|
return (result: R) => unwrapErrOrImpl(result, defaultValue);
|
|
53
58
|
}
|
|
54
59
|
}
|
|
@@ -15,9 +15,11 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
15
15
|
*
|
|
16
16
|
* ```ts
|
|
17
17
|
* const errResult = Result.err(new Error('broken'));
|
|
18
|
+
*
|
|
18
19
|
* const okResult = Result.ok('value');
|
|
19
20
|
*
|
|
20
|
-
* assert(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
21
|
+
* assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');
|
|
22
|
+
*
|
|
21
23
|
* assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);
|
|
22
24
|
* ```
|
|
23
25
|
*
|
|
@@ -13,16 +13,17 @@ import { type UnwrapErr } from './types.mjs';
|
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
15
|
* const okResult = Result.ok('data');
|
|
16
|
+
*
|
|
16
17
|
* const errResult = Result.err('problem');
|
|
17
18
|
*
|
|
18
19
|
* // Result.unwrapErr returns undefined for Ok results
|
|
19
20
|
*
|
|
20
21
|
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
21
|
-
* assert(Result.unwrapErr(okResult) === undefined);
|
|
22
|
+
* assert.isTrue(Result.unwrapErr(okResult) === undefined);
|
|
22
23
|
*
|
|
23
24
|
* // Result.unwrapErr returns the error value for Err results
|
|
24
25
|
*
|
|
25
|
-
* assert(Result.unwrapErr(errResult) === 'problem');
|
|
26
|
+
* assert.isTrue(Result.unwrapErr(errResult) === 'problem');
|
|
26
27
|
* ```
|
|
27
28
|
*
|
|
28
29
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -9,15 +9,18 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
11
|
* const okValue = Result.ok(10);
|
|
12
|
+
*
|
|
12
13
|
* const errValue = Result.err('fail');
|
|
13
14
|
*
|
|
14
|
-
* assert(Result.unwrapOkOr(okValue, 0) === 10);
|
|
15
|
-
*
|
|
15
|
+
* assert.isTrue(Result.unwrapOkOr(okValue, 0) === 10);
|
|
16
|
+
*
|
|
17
|
+
* assert.isTrue(Result.unwrapOkOr(errValue, 0) === 0);
|
|
16
18
|
*
|
|
17
19
|
* const unwrapWithDefault = Result.unwrapOkOr(5);
|
|
18
20
|
*
|
|
19
|
-
* assert(unwrapWithDefault(Result.ok(3)) === 3);
|
|
20
|
-
*
|
|
21
|
+
* assert.isTrue(unwrapWithDefault(Result.ok(3)) === 3);
|
|
22
|
+
*
|
|
23
|
+
* assert.isTrue(unwrapWithDefault(Result.err('no data')) === 5);
|
|
21
24
|
* ```
|
|
22
25
|
*
|
|
23
26
|
* @template R The `UnknownResult` type to unwrap.
|
|
@@ -43,12 +46,14 @@ export function unwrapOkOr<R extends UnknownResult, D>(
|
|
|
43
46
|
case 2: {
|
|
44
47
|
// Direct version: first argument is result
|
|
45
48
|
const [result, defaultValue] = args;
|
|
49
|
+
|
|
46
50
|
return unwrapOkOrImpl(result, defaultValue);
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
case 1: {
|
|
50
54
|
// Curried version
|
|
51
55
|
const [defaultValue] = args;
|
|
56
|
+
|
|
52
57
|
return (result: R) => unwrapOkOrImpl(result, defaultValue);
|
|
53
58
|
}
|
|
54
59
|
}
|
|
@@ -8,19 +8,21 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const okResult = Result.ok(42);
|
|
11
|
+
*
|
|
11
12
|
* const errResult = Result.err('oops');
|
|
12
13
|
*
|
|
13
14
|
* // Result.unwrapOk returns the value for Ok results
|
|
14
15
|
*
|
|
15
|
-
* assert(Result.unwrapOk(okResult) === 42);
|
|
16
|
+
* assert.isTrue(Result.unwrapOk(okResult) === 42);
|
|
16
17
|
*
|
|
17
18
|
* // Result.unwrapOk returns undefined for Err results
|
|
18
19
|
*
|
|
19
20
|
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
20
|
-
* assert(Result.unwrapOk(errResult) === undefined);
|
|
21
|
+
* assert.isTrue(Result.unwrapOk(errResult) === undefined);
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
24
|
export function unwrapOk<R extends Ok<unknown>>(result: R): UnwrapOk<R>;
|
|
25
|
+
|
|
24
26
|
export function unwrapOk<R extends UnknownResult>(
|
|
25
27
|
result: R,
|
|
26
28
|
): UnwrapOk<R> | undefined;
|
|
@@ -15,9 +15,11 @@ import { type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
|
15
15
|
*
|
|
16
16
|
* ```ts
|
|
17
17
|
* const okResult = Result.ok('data');
|
|
18
|
+
*
|
|
18
19
|
* const errResult = Result.err(new Error('fail'));
|
|
19
20
|
*
|
|
20
|
-
* assert(Result.unwrapThrow(okResult) === 'data');
|
|
21
|
+
* assert.isTrue(Result.unwrapThrow(okResult) === 'data');
|
|
22
|
+
*
|
|
21
23
|
* assert.throws(() => Result.unwrapThrow(errResult), /fail/u);
|
|
22
24
|
* ```
|
|
23
25
|
*
|
|
@@ -9,11 +9,13 @@ import { ok } from './result-ok.mjs';
|
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
11
|
* const first = Result.ok('left');
|
|
12
|
+
*
|
|
12
13
|
* const second = Result.ok(1);
|
|
13
14
|
*
|
|
14
|
-
* const expected
|
|
15
|
+
* const expected = ['left', 1] as const;
|
|
15
16
|
*
|
|
16
17
|
* assert.deepStrictEqual(Result.zip(first, second), Result.ok(expected));
|
|
18
|
+
*
|
|
17
19
|
* assert.deepStrictEqual(
|
|
18
20
|
* Result.zip(first, Result.err('error')),
|
|
19
21
|
* Result.err('error'),
|