ts-data-forge 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -6
- 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 +7 -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 +1 -0
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +26 -2
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +2 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +30 -0
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +1 -0
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +13 -0
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +13 -0
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +3 -0
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +3 -0
- 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 +15 -0
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +7 -0
- 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 +7 -0
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +17 -0
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +11 -0
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs +1 -0
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +20 -0
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +3 -0
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +27 -0
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +7 -0
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +29 -0
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +7 -0
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +40 -0
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +9 -0
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +35 -0
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +8 -0
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +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 +1 -0
- 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-optional.d.mts +2 -0
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +2 -0
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +1 -0
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +1 -0
- 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 +2 -0
- package/dist/functional/optional/impl/optional-none.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +2 -0
- 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 +3 -1
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +2 -0
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +2 -0
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +2 -0
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +3 -0
- 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 +1 -0
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +1 -0
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +2 -0
- 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 +2 -0
- package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +2 -0
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/result/impl/result-err.d.mts +3 -1
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +2 -0
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +1 -0
- 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 +3 -0
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +3 -0
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +2 -0
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +4 -1
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +2 -0
- package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +2 -0
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +2 -0
- package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +2 -0
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts +4 -0
- package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +4 -0
- 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 +3 -1
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +2 -0
- 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 +3 -0
- 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 +2 -0
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +2 -0
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +1 -0
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +1 -0
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +3 -0
- 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 +1 -0
- 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 +2 -0
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +2 -0
- 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 +2 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +1 -0
- 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 +2 -0
- 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 +2 -0
- 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 +2 -0
- 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 +4 -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 +4 -0
- 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 +4 -0
- 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 +10 -0
- 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 +1 -0
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +1 -0
- 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 +21 -0
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +22 -0
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +14 -0
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +14 -0
- 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 +14 -0
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +14 -0
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +21 -0
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +22 -1
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +21 -0
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +23 -2
- 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 +12 -0
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +12 -0
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/num.d.mts +9 -0
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +8 -1
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +22 -0
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +23 -0
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +9 -0
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +7 -0
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/tuple.d.mts +11 -0
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +11 -0
- 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 +2 -1
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/promise.d.mts +4 -0
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +5 -0
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +20 -24
- package/src/array/impl/array-utils-creation.mts +20 -0
- package/src/array/impl/array-utils-creation.test.mts +71 -0
- package/src/array/impl/array-utils-element-access.mts +13 -0
- package/src/array/impl/array-utils-element-access.test.mts +21 -0
- package/src/array/impl/array-utils-iterators.test.mts +17 -0
- package/src/array/impl/array-utils-modification.mts +40 -0
- 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 +55 -9
- package/src/array/impl/array-utils-reducing-value.test.mts +90 -0
- package/src/array/impl/array-utils-search.mts +53 -0
- package/src/array/impl/array-utils-search.test.mts +51 -0
- package/src/array/impl/array-utils-set-op.mts +19 -0
- package/src/array/impl/array-utils-set-op.test.mts +116 -0
- package/src/array/impl/array-utils-size.mts +3 -0
- 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 +27 -0
- 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 +113 -1
- package/src/array/impl/array-utils-validation.mts +23 -0
- package/src/array/impl/array-utils-validation.test.mts +96 -0
- package/src/array/impl/array.test.mts +12 -0
- package/src/collections/imap-mapped.mts +11 -0
- package/src/collections/imap-mapped.test.mts +70 -0
- package/src/collections/imap.mts +32 -0
- package/src/collections/imap.test.mts +106 -0
- package/src/collections/iset-mapped.mts +35 -0
- package/src/collections/iset-mapped.test.mts +111 -0
- package/src/collections/iset.mts +34 -0
- package/src/collections/iset.test.mts +193 -0
- package/src/collections/queue.mts +53 -0
- package/src/collections/queue.test.mts +32 -0
- package/src/collections/stack.mts +42 -0
- package/src/collections/stack.test.mts +44 -0
- package/src/functional/match.mts +16 -0
- package/src/functional/match.test.mts +2 -0
- package/src/functional/optional/impl/optional-expect-to-be.mts +3 -0
- 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-optional.mts +2 -0
- package/src/functional/optional/impl/optional-is-some.mts +1 -0
- package/src/functional/optional/impl/optional-map.mts +5 -0
- package/src/functional/optional/impl/optional-none.mts +2 -0
- package/src/functional/optional/impl/optional-or-else.mts +6 -0
- package/src/functional/optional/impl/optional-some.mts +3 -1
- package/src/functional/optional/impl/optional-to-nullable.mts +2 -0
- package/src/functional/optional/impl/optional-unwrap-or.mts +5 -0
- package/src/functional/optional/impl/optional-unwrap-throw.mts +1 -0
- package/src/functional/optional/impl/optional-unwrap.mts +2 -0
- package/src/functional/optional/impl/optional-zip.mts +2 -0
- package/src/functional/optional.test.mts +73 -0
- package/src/functional/pipe.test.mts +3 -0
- package/src/functional/result/impl/result-err.mts +3 -1
- package/src/functional/result/impl/result-expect-to-be.mts +3 -0
- 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 +3 -0
- package/src/functional/result/impl/result-from-throwable.mts +6 -1
- package/src/functional/result/impl/result-is-err.mts +2 -0
- package/src/functional/result/impl/result-is-ok.mts +2 -0
- package/src/functional/result/impl/result-is-result.mts +4 -0
- 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 +3 -1
- 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 +5 -0
- package/src/functional/result/impl/result-unwrap-err-throw.mts +2 -0
- package/src/functional/result/impl/result-unwrap-err.mts +1 -0
- package/src/functional/result/impl/result-unwrap-ok-or.mts +5 -0
- package/src/functional/result/impl/result-unwrap-ok.mts +2 -0
- package/src/functional/result/impl/result-unwrap-throw.mts +2 -0
- package/src/functional/result/impl/result-zip.mts +3 -1
- package/src/functional/result.test.mts +88 -0
- package/src/functional/ternary-result/impl/ternary-result-err.mts +2 -1
- 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 +2 -0
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +5 -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 +4 -0
- 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 +91 -0
- package/src/globals.d.mts +10 -0
- package/src/guard/has-key.test.mts +9 -0
- package/src/guard/is-non-empty-string.test.mts +20 -0
- package/src/guard/is-non-null-object.test.mts +19 -0
- package/src/guard/is-primitive.test.mts +23 -0
- package/src/guard/is-record.mts +34 -0
- package/src/guard/is-record.test.mts +21 -0
- package/src/guard/is-type.mts +3 -0
- package/src/guard/is-type.test.mts +134 -0
- package/src/guard/key-is-in.mts +1 -0
- package/src/iterator/range.mts +9 -0
- package/src/json/json.mts +29 -0
- package/src/json/json.test.mts +87 -0
- package/src/number/branded-types/finite-number.test.mts +38 -0
- package/src/number/branded-types/int.mts +14 -0
- package/src/number/branded-types/int.test.mts +42 -0
- package/src/number/branded-types/int16.test.mts +47 -0
- package/src/number/branded-types/int32.test.mts +47 -0
- package/src/number/branded-types/non-negative-finite-number.test.mts +40 -0
- package/src/number/branded-types/non-negative-int16.test.mts +43 -0
- package/src/number/branded-types/non-negative-int32.test.mts +43 -0
- package/src/number/branded-types/non-zero-finite-number.test.mts +51 -0
- package/src/number/branded-types/non-zero-int.test.mts +53 -0
- package/src/number/branded-types/non-zero-int16.test.mts +44 -0
- package/src/number/branded-types/non-zero-int32.test.mts +44 -0
- package/src/number/branded-types/non-zero-safe-int.mts +2 -2
- package/src/number/branded-types/non-zero-safe-int.test.mts +62 -0
- package/src/number/branded-types/non-zero-uint16.test.mts +37 -0
- package/src/number/branded-types/non-zero-uint32.test.mts +37 -0
- package/src/number/branded-types/positive-finite-number.test.mts +45 -0
- package/src/number/branded-types/positive-int.mts +14 -0
- package/src/number/branded-types/positive-int.test.mts +47 -0
- package/src/number/branded-types/positive-int16.test.mts +35 -0
- package/src/number/branded-types/positive-int32.test.mts +35 -0
- package/src/number/branded-types/positive-safe-int.mts +22 -1
- package/src/number/branded-types/positive-safe-int.test.mts +49 -0
- package/src/number/branded-types/positive-uint16.test.mts +37 -0
- package/src/number/branded-types/positive-uint32.test.mts +37 -0
- package/src/number/branded-types/safe-int.mts +23 -2
- package/src/number/branded-types/safe-int.test.mts +52 -0
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/branded-types/safe-uint.test.mts +48 -0
- package/src/number/branded-types/uint.mts +12 -0
- package/src/number/branded-types/uint.test.mts +43 -0
- package/src/number/branded-types/uint16.test.mts +41 -0
- package/src/number/branded-types/uint32.test.mts +41 -0
- package/src/number/enum/int8.test.mts +6 -0
- package/src/number/enum/uint8.test.mts +6 -0
- package/src/number/num.mts +12 -1
- package/src/number/num.test.mts +62 -0
- package/src/number/refined-number-utils.mts +25 -0
- package/src/object/object.mts +15 -0
- package/src/object/object.test.mts +10 -0
- package/src/others/cast-mutable.test.mts +7 -0
- package/src/others/cast-readonly.test.mts +17 -0
- package/src/others/if-then.test.mts +16 -0
- 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 +11 -0
- package/src/others/unknown-to-string.mts +4 -1
- package/src/others/unknown-to-string.test.mts +10 -0
- package/src/promise/promise.mts +4 -0
- package/src/promise/promise.test.mts +1 -0
|
@@ -6,8 +6,11 @@ describe('Optional test', () => {
|
|
|
6
6
|
describe('isOptional', () => {
|
|
7
7
|
test('should return true for Some values', () => {
|
|
8
8
|
expect(Optional.isOptional(Optional.some(42))).toBe(true);
|
|
9
|
+
|
|
9
10
|
expect(Optional.isOptional(Optional.some('hello'))).toBe(true);
|
|
11
|
+
|
|
10
12
|
expect(Optional.isOptional(Optional.some(null))).toBe(true);
|
|
13
|
+
|
|
11
14
|
expect(Optional.isOptional(Optional.some(undefined))).toBe(true);
|
|
12
15
|
});
|
|
13
16
|
|
|
@@ -17,10 +20,15 @@ describe('Optional test', () => {
|
|
|
17
20
|
|
|
18
21
|
test('should return false for non-Optional values', () => {
|
|
19
22
|
expect(Optional.isOptional(42)).toBe(false);
|
|
23
|
+
|
|
20
24
|
expect(Optional.isOptional('hello')).toBe(false);
|
|
25
|
+
|
|
21
26
|
expect(Optional.isOptional(null)).toBe(false);
|
|
27
|
+
|
|
22
28
|
expect(Optional.isOptional(undefined)).toBe(false);
|
|
29
|
+
|
|
23
30
|
expect(Optional.isOptional({})).toBe(false);
|
|
31
|
+
|
|
24
32
|
expect(Optional.isOptional({ type: 'fake', value: 42 })).toBe(false);
|
|
25
33
|
});
|
|
26
34
|
});
|
|
@@ -30,11 +38,13 @@ describe('Optional test', () => {
|
|
|
30
38
|
const someNumber = Optional.some(42);
|
|
31
39
|
|
|
32
40
|
expect(Optional.isSome(someNumber)).toBe(true);
|
|
41
|
+
|
|
33
42
|
expect(Optional.unwrap(someNumber)).toBe(42);
|
|
34
43
|
|
|
35
44
|
const someString = Optional.some('hello');
|
|
36
45
|
|
|
37
46
|
expect(Optional.isSome(someString)).toBe(true);
|
|
47
|
+
|
|
38
48
|
expect(Optional.unwrap(someString)).toBe('hello');
|
|
39
49
|
|
|
40
50
|
const someObject = Optional.some({ name: 'Alice', age: 30 });
|
|
@@ -57,7 +67,9 @@ describe('Optional test', () => {
|
|
|
57
67
|
describe('none', () => {
|
|
58
68
|
test('should be a singleton None value', () => {
|
|
59
69
|
expect(Optional.isNone(Optional.none)).toBe(true);
|
|
70
|
+
|
|
60
71
|
expect(Optional.isSome(Optional.none)).toBe(false);
|
|
72
|
+
|
|
61
73
|
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
62
74
|
expect(Optional.unwrapOr(Optional.none, undefined)).toBeUndefined();
|
|
63
75
|
});
|
|
@@ -72,6 +84,7 @@ describe('Optional test', () => {
|
|
|
72
84
|
const some = Optional.some(42);
|
|
73
85
|
|
|
74
86
|
expect(Optional.isSome(some)).toBe(true);
|
|
87
|
+
|
|
75
88
|
expect(Optional.isNone(some)).toBe(false);
|
|
76
89
|
});
|
|
77
90
|
|
|
@@ -79,6 +92,7 @@ describe('Optional test', () => {
|
|
|
79
92
|
const none = Optional.none;
|
|
80
93
|
|
|
81
94
|
expect(Optional.isSome(none)).toBe(false);
|
|
95
|
+
|
|
82
96
|
expect(Optional.isNone(none)).toBe(true);
|
|
83
97
|
});
|
|
84
98
|
|
|
@@ -98,6 +112,7 @@ describe('Optional test', () => {
|
|
|
98
112
|
describe('map', () => {
|
|
99
113
|
test('should map over Some values', () => {
|
|
100
114
|
const some = Optional.some(5);
|
|
115
|
+
|
|
101
116
|
const mapped = Optional.map(some, (x) => x * 2);
|
|
102
117
|
|
|
103
118
|
expect(Optional.isSome(mapped)).toBe(true);
|
|
@@ -109,6 +124,7 @@ describe('Optional test', () => {
|
|
|
109
124
|
|
|
110
125
|
test('should return None for None values', () => {
|
|
111
126
|
const none = Optional.none;
|
|
127
|
+
|
|
112
128
|
const mapped = Optional.map(none, (x: never) => x * 2);
|
|
113
129
|
|
|
114
130
|
expect(Optional.isNone(mapped)).toBe(true);
|
|
@@ -137,6 +153,7 @@ describe('Optional test', () => {
|
|
|
137
153
|
const doubler = Optional.map((x: number) => x * 2);
|
|
138
154
|
|
|
139
155
|
const some = Optional.some(5);
|
|
156
|
+
|
|
140
157
|
const mapped = doubler(some);
|
|
141
158
|
|
|
142
159
|
expect(Optional.isSome(mapped)).toBe(true);
|
|
@@ -146,6 +163,7 @@ describe('Optional test', () => {
|
|
|
146
163
|
}
|
|
147
164
|
|
|
148
165
|
const none = Optional.none;
|
|
166
|
+
|
|
149
167
|
const mappedNone = doubler(none);
|
|
150
168
|
|
|
151
169
|
expect(Optional.isNone(mappedNone)).toBe(true);
|
|
@@ -153,6 +171,7 @@ describe('Optional test', () => {
|
|
|
153
171
|
|
|
154
172
|
test('should work with pipe when curried', () => {
|
|
155
173
|
const doubler = Optional.map((x: number) => x * 2);
|
|
174
|
+
|
|
156
175
|
const toStringFn = Optional.map((x: number) => x.toString());
|
|
157
176
|
|
|
158
177
|
const result = pipe(Optional.some(5)).map(doubler).map(toStringFn).value;
|
|
@@ -168,7 +187,9 @@ describe('Optional test', () => {
|
|
|
168
187
|
describe('unwrap', () => {
|
|
169
188
|
test('should return the value for Some', () => {
|
|
170
189
|
expect(Optional.unwrap(Optional.some(42))).toBe(42);
|
|
190
|
+
|
|
171
191
|
expect(Optional.unwrap(Optional.some('hello'))).toBe('hello');
|
|
192
|
+
|
|
172
193
|
expect(Optional.unwrap(Optional.some(null))).toBeNull();
|
|
173
194
|
});
|
|
174
195
|
|
|
@@ -192,6 +213,7 @@ describe('Optional test', () => {
|
|
|
192
213
|
describe('unwrapThrow', () => {
|
|
193
214
|
test('should return the value for Some', () => {
|
|
194
215
|
expect(Optional.unwrapThrow(Optional.some(42))).toBe(42);
|
|
216
|
+
|
|
195
217
|
expect(Optional.unwrapThrow(Optional.some('hello'))).toBe('hello');
|
|
196
218
|
});
|
|
197
219
|
|
|
@@ -211,6 +233,7 @@ describe('Optional test', () => {
|
|
|
211
233
|
describe('unwrapOr', () => {
|
|
212
234
|
test('should return the value for Some', () => {
|
|
213
235
|
expect(Optional.unwrapOr(Optional.some(42), 0)).toBe(42);
|
|
236
|
+
|
|
214
237
|
expect(Optional.unwrapOr(Optional.some('hello'), 'default')).toBe(
|
|
215
238
|
'hello',
|
|
216
239
|
);
|
|
@@ -218,6 +241,7 @@ describe('Optional test', () => {
|
|
|
218
241
|
|
|
219
242
|
test('should return the default value for None', () => {
|
|
220
243
|
expect(Optional.unwrapOr(Optional.none, 0)).toBe(0);
|
|
244
|
+
|
|
221
245
|
expect(Optional.unwrapOr(Optional.none, 'default')).toBe('default');
|
|
222
246
|
});
|
|
223
247
|
|
|
@@ -239,11 +263,13 @@ describe('Optional test', () => {
|
|
|
239
263
|
const unwrapWithDefault = Optional.unwrapOr(42);
|
|
240
264
|
|
|
241
265
|
const someValue = Optional.some(100);
|
|
266
|
+
|
|
242
267
|
const result = unwrapWithDefault(someValue);
|
|
243
268
|
|
|
244
269
|
expect(result).toBe(100);
|
|
245
270
|
|
|
246
271
|
const noneValue = Optional.none;
|
|
272
|
+
|
|
247
273
|
const defaultResult = unwrapWithDefault(noneValue);
|
|
248
274
|
|
|
249
275
|
expect(defaultResult).toBe(42);
|
|
@@ -281,9 +307,11 @@ describe('Optional test', () => {
|
|
|
281
307
|
const expectValidId = Optional.expectToBe<string>('ID is required');
|
|
282
308
|
|
|
283
309
|
const id1 = Optional.some('user-123');
|
|
310
|
+
|
|
284
311
|
const id2 = Optional.none;
|
|
285
312
|
|
|
286
313
|
expect(expectValidId(id1)).toBe('user-123');
|
|
314
|
+
|
|
287
315
|
expect(() => expectValidId(id2)).toThrow('ID is required');
|
|
288
316
|
});
|
|
289
317
|
|
|
@@ -291,6 +319,7 @@ describe('Optional test', () => {
|
|
|
291
319
|
const getValue = Optional.expectToBe('Value must exist');
|
|
292
320
|
|
|
293
321
|
const someValue = Optional.some('important data');
|
|
322
|
+
|
|
294
323
|
const result = getValue(someValue);
|
|
295
324
|
|
|
296
325
|
expect(result).toBe('important data');
|
|
@@ -318,10 +347,13 @@ describe('Optional test', () => {
|
|
|
318
347
|
describe('type utilities', () => {
|
|
319
348
|
test('should correctly unwrap types', () => {
|
|
320
349
|
type SomeNumber = Some<number>;
|
|
350
|
+
|
|
321
351
|
type UnwrappedNumber = Optional.Unwrap<SomeNumber>;
|
|
352
|
+
|
|
322
353
|
expectType<UnwrappedNumber, number>('=');
|
|
323
354
|
|
|
324
355
|
type UnwrappedNone = Optional.Unwrap<None>;
|
|
356
|
+
|
|
325
357
|
expectType<UnwrappedNone, never>('=');
|
|
326
358
|
});
|
|
327
359
|
|
|
@@ -329,9 +361,11 @@ describe('Optional test', () => {
|
|
|
329
361
|
type MaybeNumber = Optional<number>;
|
|
330
362
|
|
|
331
363
|
type OnlySome = Optional.NarrowToSome<MaybeNumber>;
|
|
364
|
+
|
|
332
365
|
expectType<OnlySome, Some<number>>('=');
|
|
333
366
|
|
|
334
367
|
type OnlyNone = Optional.NarrowToNone<MaybeNumber>;
|
|
368
|
+
|
|
335
369
|
expectType<OnlyNone, None>('=');
|
|
336
370
|
});
|
|
337
371
|
});
|
|
@@ -340,10 +374,12 @@ describe('Optional test', () => {
|
|
|
340
374
|
test('should chain operations that return Optional', () => {
|
|
341
375
|
const parseNumber = (s: string): Optional<number> => {
|
|
342
376
|
const n = Number(s);
|
|
377
|
+
|
|
343
378
|
return Number.isNaN(n) ? Optional.none : Optional.some(n);
|
|
344
379
|
};
|
|
345
380
|
|
|
346
381
|
const result = Optional.flatMap(Optional.some('42'), parseNumber);
|
|
382
|
+
|
|
347
383
|
if (Optional.isSome(result)) {
|
|
348
384
|
expect(Optional.unwrap(result)).toBe(42);
|
|
349
385
|
}
|
|
@@ -364,6 +400,7 @@ describe('Optional test', () => {
|
|
|
364
400
|
test('should support chaining multiple flatMaps', () => {
|
|
365
401
|
const parseNumber = (s: string): Optional<number> => {
|
|
366
402
|
const n = Number(s);
|
|
403
|
+
|
|
367
404
|
return Number.isNaN(n) ? Optional.none : Optional.some(n);
|
|
368
405
|
};
|
|
369
406
|
|
|
@@ -376,7 +413,9 @@ describe('Optional test', () => {
|
|
|
376
413
|
Optional.some(n / divisor);
|
|
377
414
|
|
|
378
415
|
const intermediate = Optional.flatMap(Optional.some('100'), parseNumber);
|
|
416
|
+
|
|
379
417
|
const result = Optional.flatMap(intermediate, divideBy(2));
|
|
418
|
+
|
|
380
419
|
if (Optional.isSome(result)) {
|
|
381
420
|
expect(Optional.unwrap(result)).toBe(50);
|
|
382
421
|
}
|
|
@@ -385,6 +424,7 @@ describe('Optional test', () => {
|
|
|
385
424
|
test('should support curried form', () => {
|
|
386
425
|
const parseNumber = (s: string): Optional<number> => {
|
|
387
426
|
const n = Number(s);
|
|
427
|
+
|
|
388
428
|
return Number.isNaN(n) ? Optional.none : Optional.some(n);
|
|
389
429
|
};
|
|
390
430
|
|
|
@@ -410,6 +450,7 @@ describe('Optional test', () => {
|
|
|
410
450
|
test('should work with pipe when curried', () => {
|
|
411
451
|
const parseNumber = (s: string): Optional<number> => {
|
|
412
452
|
const n = Number(s);
|
|
453
|
+
|
|
413
454
|
return Number.isNaN(n) ? Optional.none : Optional.some(n);
|
|
414
455
|
};
|
|
415
456
|
|
|
@@ -417,6 +458,7 @@ describe('Optional test', () => {
|
|
|
417
458
|
n > 0 ? Optional.some(n * 2) : Optional.none;
|
|
418
459
|
|
|
419
460
|
const parser = Optional.flatMap(parseNumber);
|
|
461
|
+
|
|
420
462
|
const doubler = Optional.flatMap(doubleIfPositive);
|
|
421
463
|
|
|
422
464
|
const result = pipe(Optional.some('42')).map(parser).map(doubler).value;
|
|
@@ -432,7 +474,9 @@ describe('Optional test', () => {
|
|
|
432
474
|
describe('filter', () => {
|
|
433
475
|
test('should keep Some values that match predicate', () => {
|
|
434
476
|
const someEven = Optional.some(4);
|
|
477
|
+
|
|
435
478
|
const filtered = Optional.filter(someEven, (x) => x % 2 === 0);
|
|
479
|
+
|
|
436
480
|
if (Optional.isSome(filtered)) {
|
|
437
481
|
expect(Optional.unwrap(filtered)).toBe(4);
|
|
438
482
|
}
|
|
@@ -440,6 +484,7 @@ describe('Optional test', () => {
|
|
|
440
484
|
|
|
441
485
|
test('should return None for Some values that do not match predicate', () => {
|
|
442
486
|
const someOdd = Optional.some(5);
|
|
487
|
+
|
|
443
488
|
const filtered = Optional.filter(someOdd, (x) => x % 2 === 0);
|
|
444
489
|
|
|
445
490
|
expect(Optional.isNone(filtered)).toBe(true);
|
|
@@ -455,6 +500,7 @@ describe('Optional test', () => {
|
|
|
455
500
|
const evenFilter = Optional.filter((x: number) => x % 2 === 0);
|
|
456
501
|
|
|
457
502
|
const someEven = Optional.some(4);
|
|
503
|
+
|
|
458
504
|
const filtered = evenFilter(someEven);
|
|
459
505
|
|
|
460
506
|
expect(Optional.isSome(filtered)).toBe(true);
|
|
@@ -464,6 +510,7 @@ describe('Optional test', () => {
|
|
|
464
510
|
}
|
|
465
511
|
|
|
466
512
|
const someOdd = Optional.some(5);
|
|
513
|
+
|
|
467
514
|
const filteredOdd = evenFilter(someOdd);
|
|
468
515
|
|
|
469
516
|
expect(Optional.isNone(filteredOdd)).toBe(true);
|
|
@@ -475,6 +522,7 @@ describe('Optional test', () => {
|
|
|
475
522
|
|
|
476
523
|
test('should work with pipe when curried', () => {
|
|
477
524
|
const evenFilter = Optional.filter((x: number) => x % 2 === 0);
|
|
525
|
+
|
|
478
526
|
const positiveFilter = Optional.filter((x: number) => x > 0);
|
|
479
527
|
|
|
480
528
|
const result = pipe(Optional.some(4))
|
|
@@ -496,8 +544,11 @@ describe('Optional test', () => {
|
|
|
496
544
|
describe('orElse', () => {
|
|
497
545
|
test('should return the first Optional if it is Some', () => {
|
|
498
546
|
const primary = Optional.some(42);
|
|
547
|
+
|
|
499
548
|
const fallback = Optional.some(100);
|
|
549
|
+
|
|
500
550
|
const result = Optional.orElse(primary, fallback);
|
|
551
|
+
|
|
501
552
|
if (Optional.isSome(result)) {
|
|
502
553
|
expect(Optional.unwrap(result)).toBe(42);
|
|
503
554
|
}
|
|
@@ -505,8 +556,11 @@ describe('Optional test', () => {
|
|
|
505
556
|
|
|
506
557
|
test('should return the alternative if the first is None', () => {
|
|
507
558
|
const primary = Optional.none;
|
|
559
|
+
|
|
508
560
|
const fallback = Optional.some('default');
|
|
561
|
+
|
|
509
562
|
const result = Optional.orElse(primary, fallback);
|
|
563
|
+
|
|
510
564
|
if (Optional.isSome(result)) {
|
|
511
565
|
expect(Optional.unwrap(result)).toBe('default');
|
|
512
566
|
}
|
|
@@ -522,6 +576,7 @@ describe('Optional test', () => {
|
|
|
522
576
|
const fallbackTo = Optional.orElse(Optional.some('fallback'));
|
|
523
577
|
|
|
524
578
|
const someValue = Optional.some('primary');
|
|
579
|
+
|
|
525
580
|
const result = fallbackTo(someValue);
|
|
526
581
|
|
|
527
582
|
expect(Optional.isSome(result)).toBe(true);
|
|
@@ -531,6 +586,7 @@ describe('Optional test', () => {
|
|
|
531
586
|
}
|
|
532
587
|
|
|
533
588
|
const noneValue = Optional.none;
|
|
589
|
+
|
|
534
590
|
const fallbackResult = fallbackTo(noneValue);
|
|
535
591
|
|
|
536
592
|
expect(Optional.isSome(fallbackResult)).toBe(true);
|
|
@@ -564,8 +620,11 @@ describe('Optional test', () => {
|
|
|
564
620
|
describe('zip', () => {
|
|
565
621
|
test('should combine two Some values into a tuple', () => {
|
|
566
622
|
const a = Optional.some(1);
|
|
623
|
+
|
|
567
624
|
const b = Optional.some('hello');
|
|
625
|
+
|
|
568
626
|
const zipped = Optional.zip(a, b);
|
|
627
|
+
|
|
569
628
|
if (Optional.isSome(zipped)) {
|
|
570
629
|
assert.deepStrictEqual(Optional.unwrap(zipped), [1, 'hello']);
|
|
571
630
|
}
|
|
@@ -573,7 +632,9 @@ describe('Optional test', () => {
|
|
|
573
632
|
|
|
574
633
|
test('should return None if first is None', () => {
|
|
575
634
|
const a = Optional.none;
|
|
635
|
+
|
|
576
636
|
const b = Optional.some('hello');
|
|
637
|
+
|
|
577
638
|
const zipped = Optional.zip(a, b);
|
|
578
639
|
|
|
579
640
|
expect(Optional.isNone(zipped)).toBe(true);
|
|
@@ -581,7 +642,9 @@ describe('Optional test', () => {
|
|
|
581
642
|
|
|
582
643
|
test('should return None if second is None', () => {
|
|
583
644
|
const a = Optional.some(1);
|
|
645
|
+
|
|
584
646
|
const b = Optional.none;
|
|
647
|
+
|
|
585
648
|
const zipped = Optional.zip(a, b);
|
|
586
649
|
|
|
587
650
|
expect(Optional.isNone(zipped)).toBe(true);
|
|
@@ -597,19 +660,24 @@ describe('Optional test', () => {
|
|
|
597
660
|
describe('fromNullable', () => {
|
|
598
661
|
test('should convert non-null values to Some', () => {
|
|
599
662
|
const helloOpt = Optional.fromNullable('hello');
|
|
663
|
+
|
|
600
664
|
if (Optional.isSome(helloOpt))
|
|
601
665
|
expect(Optional.unwrap(helloOpt)).toBe('hello');
|
|
602
666
|
|
|
603
667
|
const numOpt = Optional.fromNullable(42);
|
|
668
|
+
|
|
604
669
|
if (Optional.isSome(numOpt)) expect(Optional.unwrap(numOpt)).toBe(42);
|
|
605
670
|
|
|
606
671
|
const zeroOpt = Optional.fromNullable(0);
|
|
672
|
+
|
|
607
673
|
if (Optional.isSome(zeroOpt)) expect(Optional.unwrap(zeroOpt)).toBe(0);
|
|
608
674
|
|
|
609
675
|
const emptyOpt = Optional.fromNullable('');
|
|
676
|
+
|
|
610
677
|
if (Optional.isSome(emptyOpt)) expect(Optional.unwrap(emptyOpt)).toBe('');
|
|
611
678
|
|
|
612
679
|
const falseOpt = Optional.fromNullable(false);
|
|
680
|
+
|
|
613
681
|
if (Optional.isSome(falseOpt))
|
|
614
682
|
expect(Optional.unwrap(falseOpt)).toBe(false);
|
|
615
683
|
});
|
|
@@ -632,7 +700,9 @@ describe('Optional test', () => {
|
|
|
632
700
|
describe('toNullable', () => {
|
|
633
701
|
test('should convert Some to its value', () => {
|
|
634
702
|
expect(Optional.toNullable(Optional.some(42))).toBe(42);
|
|
703
|
+
|
|
635
704
|
expect(Optional.toNullable(Optional.some('hello'))).toBe('hello');
|
|
705
|
+
|
|
636
706
|
expect(Optional.toNullable(Optional.some(null))).toBeNull();
|
|
637
707
|
});
|
|
638
708
|
|
|
@@ -653,6 +723,7 @@ describe('Optional test', () => {
|
|
|
653
723
|
const someUndefined = Optional.some(undefined);
|
|
654
724
|
|
|
655
725
|
expect(Optional.isSome(someUndefined)).toBe(true);
|
|
726
|
+
|
|
656
727
|
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
657
728
|
expect(Optional.unwrap(someUndefined)).toBeUndefined();
|
|
658
729
|
|
|
@@ -664,6 +735,7 @@ describe('Optional test', () => {
|
|
|
664
735
|
const someNull = Optional.some(null);
|
|
665
736
|
|
|
666
737
|
expect(Optional.isSome(someNull)).toBe(true);
|
|
738
|
+
|
|
667
739
|
expect(Optional.unwrap(someNull)).toBeNull();
|
|
668
740
|
});
|
|
669
741
|
|
|
@@ -675,6 +747,7 @@ describe('Optional test', () => {
|
|
|
675
747
|
const inner = Optional.unwrap(nested);
|
|
676
748
|
|
|
677
749
|
expect(Optional.isOptional(inner)).toBe(true);
|
|
750
|
+
|
|
678
751
|
expect(Optional.unwrap(inner)).toBe(42);
|
|
679
752
|
});
|
|
680
753
|
});
|
|
@@ -61,6 +61,7 @@ describe(pipe, () => {
|
|
|
61
61
|
|
|
62
62
|
test('mapOptional with Some value', () => {
|
|
63
63
|
const optional = Optional.some(42);
|
|
64
|
+
|
|
64
65
|
const result = pipe(optional).mapOptional((x) => x * 2).value;
|
|
65
66
|
|
|
66
67
|
expect(Optional.isSome(result)).toBe(true);
|
|
@@ -68,11 +69,13 @@ describe(pipe, () => {
|
|
|
68
69
|
if (Optional.isSome(result)) {
|
|
69
70
|
expect(result.value).toBe(84);
|
|
70
71
|
}
|
|
72
|
+
|
|
71
73
|
expectType<typeof result, Optional<number>>('=');
|
|
72
74
|
});
|
|
73
75
|
|
|
74
76
|
test('mapOptional with None value', () => {
|
|
75
77
|
const optional: Optional<number> = Optional.none;
|
|
78
|
+
|
|
76
79
|
const result = pipe(optional).mapOptional((x) => x * 2).value;
|
|
77
80
|
|
|
78
81
|
expect(Optional.isNone(result)).toBe(true);
|
|
@@ -10,12 +10,14 @@ import { ErrTypeTagName } 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
|
* });
|
|
20
|
+
*
|
|
19
21
|
* assert.ok(Result.isErr(failure));
|
|
20
22
|
* ```
|
|
21
23
|
*
|
|
@@ -23,7 +25,7 @@ import { ErrTypeTagName } from './tag.mjs';
|
|
|
23
25
|
* @param value The error value.
|
|
24
26
|
* @returns A `Result.Err<E>` containing the value.
|
|
25
27
|
*/
|
|
26
|
-
export const err = <E,>(value: E): Err<E> => ({
|
|
28
|
+
export const err = <const E,>(value: E): Err<E> => ({
|
|
27
29
|
$$tag: ErrTypeTagName,
|
|
28
30
|
value,
|
|
29
31
|
});
|
|
@@ -16,6 +16,7 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
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(expectResult(Result.ok('value')) === 'value');
|
|
20
21
|
* ```
|
|
21
22
|
*
|
|
@@ -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,12 +19,15 @@ 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'));
|
|
30
|
+
*
|
|
28
31
|
* assert.ok(Result.isErr(rejected));
|
|
29
32
|
* ```
|
|
30
33
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isError } from '@sindresorhus/is';
|
|
1
2
|
import { unknownToString } from '../../../others/index.mjs';
|
|
2
3
|
import { err } from './result-err.mjs';
|
|
3
4
|
import { ok } from './result-ok.mjs';
|
|
@@ -16,11 +17,13 @@ import { ok } from './result-ok.mjs';
|
|
|
16
17
|
*
|
|
17
18
|
* ```ts
|
|
18
19
|
* const success = Result.fromThrowable(() => 1 + 1);
|
|
20
|
+
*
|
|
19
21
|
* const failure = Result.fromThrowable(() => {
|
|
20
22
|
* throw new Error('boom');
|
|
21
23
|
* });
|
|
22
24
|
*
|
|
23
25
|
* assert.deepStrictEqual(success, Result.ok(2));
|
|
26
|
+
*
|
|
24
27
|
* assert.ok(Result.isErr(failure));
|
|
25
28
|
* ```
|
|
26
29
|
*
|
|
@@ -33,10 +36,12 @@ export const fromThrowable = <T,>(fn: () => T): Result<T, Error> => {
|
|
|
33
36
|
try {
|
|
34
37
|
return ok(fn());
|
|
35
38
|
} catch (error) {
|
|
36
|
-
if (
|
|
39
|
+
if (isError(error)) {
|
|
37
40
|
return err(error);
|
|
38
41
|
}
|
|
42
|
+
|
|
39
43
|
const msg = unknownToString(error);
|
|
44
|
+
|
|
40
45
|
return err(new Error(msg));
|
|
41
46
|
}
|
|
42
47
|
};
|
|
@@ -8,10 +8,12 @@ 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;
|
|
16
|
+
*
|
|
15
17
|
* assert(value === 3);
|
|
16
18
|
* }
|
|
17
19
|
*
|
|
@@ -8,10 +8,12 @@ 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;
|
|
16
|
+
*
|
|
15
17
|
* assert(value === 3);
|
|
16
18
|
* }
|
|
17
19
|
*
|
|
@@ -8,11 +8,15 @@ 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
16
|
* assert.ok(Result.isResult(okValue));
|
|
17
|
+
*
|
|
15
18
|
* assert.ok(Result.isResult(errValue));
|
|
19
|
+
*
|
|
16
20
|
* assert.notOk(Result.isResult(notResult));
|
|
17
21
|
* ```
|
|
18
22
|
*/
|
|
@@ -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
|
}
|