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
|
@@ -9,7 +9,9 @@ describe('Result test', () => {
|
|
|
9
9
|
const result = Result.ok(42);
|
|
10
10
|
|
|
11
11
|
expect(Result.isOk(result)).toBe(true);
|
|
12
|
+
|
|
12
13
|
expect(Result.isErr(result)).toBe(false);
|
|
14
|
+
|
|
13
15
|
expect(result.value).toBe(42);
|
|
14
16
|
|
|
15
17
|
expectType<typeof result, Result<number, never>>('<=');
|
|
@@ -19,6 +21,7 @@ describe('Result test', () => {
|
|
|
19
21
|
const result = Result.ok('success');
|
|
20
22
|
|
|
21
23
|
expect(Result.isOk(result)).toBe(true);
|
|
24
|
+
|
|
22
25
|
expect(result.value).toBe('success');
|
|
23
26
|
|
|
24
27
|
expectType<typeof result, Result<string, never>>('<=');
|
|
@@ -30,7 +33,9 @@ describe('Result test', () => {
|
|
|
30
33
|
const result = Result.err('error message');
|
|
31
34
|
|
|
32
35
|
expect(Result.isErr(result)).toBe(true);
|
|
36
|
+
|
|
33
37
|
expect(Result.isOk(result)).toBe(false);
|
|
38
|
+
|
|
34
39
|
expect(result.value).toBe('error message');
|
|
35
40
|
|
|
36
41
|
expectType<typeof result, Result<never, string>>('<=');
|
|
@@ -40,6 +45,7 @@ describe('Result test', () => {
|
|
|
40
45
|
const result = Result.err(404);
|
|
41
46
|
|
|
42
47
|
expect(Result.isErr(result)).toBe(true);
|
|
48
|
+
|
|
43
49
|
expect(result.value).toBe(404);
|
|
44
50
|
|
|
45
51
|
expectType<typeof result, Result<never, number>>('<=');
|
|
@@ -49,6 +55,7 @@ describe('Result test', () => {
|
|
|
49
55
|
describe('isOk', () => {
|
|
50
56
|
test('type guard for Ok results', () => {
|
|
51
57
|
const result: Result<number, string> = Result.ok(42);
|
|
58
|
+
|
|
52
59
|
if (Result.isOk(result)) {
|
|
53
60
|
expectType<typeof result, Ok<number>>('<=');
|
|
54
61
|
|
|
@@ -66,6 +73,7 @@ describe('Result test', () => {
|
|
|
66
73
|
describe('isErr', () => {
|
|
67
74
|
test('type guard for Err results', () => {
|
|
68
75
|
const result: Result<number, string> = Result.err('error');
|
|
76
|
+
|
|
69
77
|
if (Result.isErr(result)) {
|
|
70
78
|
expectType<typeof result, Err<string>>('<=');
|
|
71
79
|
|
|
@@ -95,10 +103,15 @@ describe('Result test', () => {
|
|
|
95
103
|
|
|
96
104
|
test('rejects non-Result values', () => {
|
|
97
105
|
expect(Result.isResult(42)).toBe(false);
|
|
106
|
+
|
|
98
107
|
expect(Result.isResult('string')).toBe(false);
|
|
108
|
+
|
|
99
109
|
expect(Result.isResult(null)).toBe(false);
|
|
110
|
+
|
|
100
111
|
expect(Result.isResult(undefined)).toBe(false);
|
|
112
|
+
|
|
101
113
|
expect(Result.isResult({})).toBe(false);
|
|
114
|
+
|
|
102
115
|
expect(Result.isResult({ type: 'unknown', value: 42 })).toBe(false);
|
|
103
116
|
});
|
|
104
117
|
});
|
|
@@ -106,6 +119,7 @@ describe('Result test', () => {
|
|
|
106
119
|
describe('map', () => {
|
|
107
120
|
test('maps Ok result', () => {
|
|
108
121
|
const result = Result.ok(5);
|
|
122
|
+
|
|
109
123
|
const mapped = Result.map(result, (x) => x * 2);
|
|
110
124
|
|
|
111
125
|
expect(Result.isOk(mapped)).toBe(true);
|
|
@@ -113,11 +127,13 @@ describe('Result test', () => {
|
|
|
113
127
|
if (Result.isOk(mapped)) {
|
|
114
128
|
expect(mapped.value).toBe(10);
|
|
115
129
|
}
|
|
130
|
+
|
|
116
131
|
expectType<typeof mapped, Result<number, never>>('<=');
|
|
117
132
|
});
|
|
118
133
|
|
|
119
134
|
test('preserves Err result', () => {
|
|
120
135
|
const result: Result<number, string> = Result.err('error');
|
|
136
|
+
|
|
121
137
|
const mapped = Result.map(result, (x) => x * 2);
|
|
122
138
|
|
|
123
139
|
expect(Result.isErr(mapped)).toBe(true);
|
|
@@ -125,6 +141,7 @@ describe('Result test', () => {
|
|
|
125
141
|
if (Result.isErr(mapped)) {
|
|
126
142
|
expect(mapped.value).toBe('error');
|
|
127
143
|
}
|
|
144
|
+
|
|
128
145
|
expectType<typeof mapped, Result<number, string>>('<=');
|
|
129
146
|
});
|
|
130
147
|
|
|
@@ -132,6 +149,7 @@ describe('Result test', () => {
|
|
|
132
149
|
const doubler = Result.map((x: number) => x * 2);
|
|
133
150
|
|
|
134
151
|
const okResult = Result.ok(5);
|
|
152
|
+
|
|
135
153
|
const mapped = doubler(okResult);
|
|
136
154
|
|
|
137
155
|
expect(Result.isOk(mapped)).toBe(true);
|
|
@@ -141,6 +159,7 @@ describe('Result test', () => {
|
|
|
141
159
|
}
|
|
142
160
|
|
|
143
161
|
const errResult: Result<number, string> = Result.err('error');
|
|
162
|
+
|
|
144
163
|
const mappedErr = doubler(errResult);
|
|
145
164
|
|
|
146
165
|
expect(Result.isErr(mappedErr)).toBe(true);
|
|
@@ -152,6 +171,7 @@ describe('Result test', () => {
|
|
|
152
171
|
|
|
153
172
|
test('should work with pipe when curried', () => {
|
|
154
173
|
const doubler = Result.map((x: number) => x * 2);
|
|
174
|
+
|
|
155
175
|
const toStringFn = Result.map((x: number) => x.toString());
|
|
156
176
|
|
|
157
177
|
const result = pipe(Result.ok(5)).map(doubler).map(toStringFn).value;
|
|
@@ -167,6 +187,7 @@ describe('Result test', () => {
|
|
|
167
187
|
describe('mapErr', () => {
|
|
168
188
|
test('maps Err result', () => {
|
|
169
189
|
const result: Result<number, string> = Result.err('error');
|
|
190
|
+
|
|
170
191
|
const mapped = Result.mapErr(result, (e) => e.toUpperCase());
|
|
171
192
|
|
|
172
193
|
expect(Result.isErr(mapped)).toBe(true);
|
|
@@ -174,11 +195,13 @@ describe('Result test', () => {
|
|
|
174
195
|
if (Result.isErr(mapped)) {
|
|
175
196
|
expect(mapped.value).toBe('ERROR');
|
|
176
197
|
}
|
|
198
|
+
|
|
177
199
|
expectType<typeof mapped, Result<number, string>>('<=');
|
|
178
200
|
});
|
|
179
201
|
|
|
180
202
|
test('preserves Ok result', () => {
|
|
181
203
|
const result: Result<number, string> = Result.ok(42);
|
|
204
|
+
|
|
182
205
|
const mapped = Result.mapErr(result, (e: string) => e.toUpperCase());
|
|
183
206
|
|
|
184
207
|
expect(Result.isOk(mapped)).toBe(true);
|
|
@@ -186,6 +209,7 @@ describe('Result test', () => {
|
|
|
186
209
|
if (Result.isOk(mapped)) {
|
|
187
210
|
expect(mapped.value).toBe(42);
|
|
188
211
|
}
|
|
212
|
+
|
|
189
213
|
expectType<typeof mapped, Result<number, string>>('~=');
|
|
190
214
|
});
|
|
191
215
|
|
|
@@ -193,6 +217,7 @@ describe('Result test', () => {
|
|
|
193
217
|
const errorUppercase = Result.mapErr((e: string) => e.toUpperCase());
|
|
194
218
|
|
|
195
219
|
const errResult: Result<number, string> = Result.err('error');
|
|
220
|
+
|
|
196
221
|
const mapped = errorUppercase(errResult);
|
|
197
222
|
|
|
198
223
|
expect(Result.isErr(mapped)).toBe(true);
|
|
@@ -202,6 +227,7 @@ describe('Result test', () => {
|
|
|
202
227
|
}
|
|
203
228
|
|
|
204
229
|
const okResult: Result<number, string> = Result.ok(42);
|
|
230
|
+
|
|
205
231
|
const mappedOk = errorUppercase(okResult);
|
|
206
232
|
|
|
207
233
|
expect(Result.isOk(mappedOk)).toBe(true);
|
|
@@ -213,6 +239,7 @@ describe('Result test', () => {
|
|
|
213
239
|
|
|
214
240
|
test('should work with pipe when curried', () => {
|
|
215
241
|
const errorUppercase = Result.mapErr((e: string) => e.toUpperCase());
|
|
242
|
+
|
|
216
243
|
const errorPrefix = Result.mapErr((e: string) => `ERROR: ${e}`);
|
|
217
244
|
|
|
218
245
|
const result = pipe(Result.err('failed'))
|
|
@@ -230,6 +257,7 @@ describe('Result test', () => {
|
|
|
230
257
|
describe('unwrapThrow', () => {
|
|
231
258
|
test('unwraps Ok result', () => {
|
|
232
259
|
const result = Result.ok(42);
|
|
260
|
+
|
|
233
261
|
const value = Result.unwrapThrow(result);
|
|
234
262
|
|
|
235
263
|
expect(value).toBe(42);
|
|
@@ -247,6 +275,7 @@ describe('Result test', () => {
|
|
|
247
275
|
describe('unwrapOkOr', () => {
|
|
248
276
|
test('unwraps Ok result', () => {
|
|
249
277
|
const result = Result.ok(42);
|
|
278
|
+
|
|
250
279
|
const value = Result.unwrapOkOr(result, 0);
|
|
251
280
|
|
|
252
281
|
expect(value).toBe(42);
|
|
@@ -256,6 +285,7 @@ describe('Result test', () => {
|
|
|
256
285
|
|
|
257
286
|
test('returns default for Err result', () => {
|
|
258
287
|
const result: Result<number, string> = Result.err('error');
|
|
288
|
+
|
|
259
289
|
const value = Result.unwrapOkOr(result, 0);
|
|
260
290
|
|
|
261
291
|
expect(value).toBe(0);
|
|
@@ -267,11 +297,13 @@ describe('Result test', () => {
|
|
|
267
297
|
const unwrapWithDefault = Result.unwrapOkOr(42);
|
|
268
298
|
|
|
269
299
|
const okResult = Result.ok(100);
|
|
300
|
+
|
|
270
301
|
const successValue = unwrapWithDefault(okResult);
|
|
271
302
|
|
|
272
303
|
expect(successValue).toBe(100);
|
|
273
304
|
|
|
274
305
|
const errResult: Result<number, string> = Result.err('failed');
|
|
306
|
+
|
|
275
307
|
const defaultValue = unwrapWithDefault(errResult);
|
|
276
308
|
|
|
277
309
|
expect(defaultValue).toBe(42);
|
|
@@ -295,6 +327,7 @@ describe('Result test', () => {
|
|
|
295
327
|
describe('unwrapErr', () => {
|
|
296
328
|
test('unwraps Err result', () => {
|
|
297
329
|
const result: Result<number, string> = Result.err('error');
|
|
330
|
+
|
|
298
331
|
const value = Result.unwrapErr(result);
|
|
299
332
|
|
|
300
333
|
expect(value).toBe('error');
|
|
@@ -317,6 +350,7 @@ describe('Result test', () => {
|
|
|
317
350
|
describe('fold', () => {
|
|
318
351
|
test('folds Ok result', () => {
|
|
319
352
|
const result = Result.ok(42);
|
|
353
|
+
|
|
320
354
|
const folded = Result.fold(
|
|
321
355
|
result,
|
|
322
356
|
(x) => x * 2,
|
|
@@ -328,11 +362,13 @@ describe('Result test', () => {
|
|
|
328
362
|
if (Result.isOk(folded)) {
|
|
329
363
|
expect(folded.value).toBe(84);
|
|
330
364
|
}
|
|
365
|
+
|
|
331
366
|
expectType<typeof folded, Result<number, number>>('=');
|
|
332
367
|
});
|
|
333
368
|
|
|
334
369
|
test('folds Err result', () => {
|
|
335
370
|
const result: Result<number, string> = Result.err('error');
|
|
371
|
+
|
|
336
372
|
const folded = Result.fold(
|
|
337
373
|
result,
|
|
338
374
|
(x) => x * 2,
|
|
@@ -344,6 +380,7 @@ describe('Result test', () => {
|
|
|
344
380
|
if (Result.isErr(folded)) {
|
|
345
381
|
expect(folded.value).toBe(5); // length of 'error'
|
|
346
382
|
}
|
|
383
|
+
|
|
347
384
|
expectType<typeof folded, Result<number, number>>('=');
|
|
348
385
|
});
|
|
349
386
|
|
|
@@ -354,6 +391,7 @@ describe('Result test', () => {
|
|
|
354
391
|
);
|
|
355
392
|
|
|
356
393
|
const okResult = Result.ok(42);
|
|
394
|
+
|
|
357
395
|
const foldedOk = folder(okResult);
|
|
358
396
|
|
|
359
397
|
expect(Result.isOk(foldedOk)).toBe(true);
|
|
@@ -363,6 +401,7 @@ describe('Result test', () => {
|
|
|
363
401
|
}
|
|
364
402
|
|
|
365
403
|
const errResult: Result<number, string> = Result.err('error');
|
|
404
|
+
|
|
366
405
|
const foldedErr = folder(errResult);
|
|
367
406
|
|
|
368
407
|
expect(Result.isErr(foldedErr)).toBe(true);
|
|
@@ -404,22 +443,26 @@ describe('Result test', () => {
|
|
|
404
443
|
const result = await Result.fromPromise(asyncFn());
|
|
405
444
|
|
|
406
445
|
expect(Result.isOk(result)).toBe(true);
|
|
446
|
+
|
|
407
447
|
expect(Result.unwrapOk(result)).toBe(42);
|
|
408
448
|
});
|
|
409
449
|
|
|
410
450
|
test('handles async functions that reject', async () => {
|
|
411
451
|
const error = new Error('Async error');
|
|
452
|
+
|
|
412
453
|
const asyncFn = async (): Promise<number> =>
|
|
413
454
|
Promise.reject(error).then(() => 42);
|
|
414
455
|
|
|
415
456
|
const result = await Result.fromPromise(asyncFn());
|
|
416
457
|
|
|
417
458
|
expect(Result.isErr(result)).toBe(true);
|
|
459
|
+
|
|
418
460
|
expect(Result.unwrapErr(result)).toBe(error);
|
|
419
461
|
});
|
|
420
462
|
|
|
421
463
|
test('works with different promise types', async () => {
|
|
422
464
|
const stringPromise = Promise.resolve('hello');
|
|
465
|
+
|
|
423
466
|
const result = await Result.fromPromise(stringPromise);
|
|
424
467
|
|
|
425
468
|
expect(Result.unwrapOk(result)).toBe('hello');
|
|
@@ -456,6 +499,7 @@ describe('Result test', () => {
|
|
|
456
499
|
test('should support chaining multiple flatMaps', () => {
|
|
457
500
|
const parseNumber = (s: string): Result<number, string> => {
|
|
458
501
|
const n = Number(s);
|
|
502
|
+
|
|
459
503
|
return Number.isNaN(n) ? Result.err('Not a number') : Result.ok(n);
|
|
460
504
|
};
|
|
461
505
|
|
|
@@ -481,6 +525,7 @@ describe('Result test', () => {
|
|
|
481
525
|
const divideBy2 = Result.flatMap((x: number) => divide(x, 2));
|
|
482
526
|
|
|
483
527
|
const okResult = Result.ok(10);
|
|
528
|
+
|
|
484
529
|
const result = divideBy2(okResult);
|
|
485
530
|
|
|
486
531
|
expect(Result.isOk(result)).toBe(true);
|
|
@@ -490,6 +535,7 @@ describe('Result test', () => {
|
|
|
490
535
|
}
|
|
491
536
|
|
|
492
537
|
const divideByZero = Result.flatMap((x: number) => divide(x, 0));
|
|
538
|
+
|
|
493
539
|
const errorResult = divideByZero(Result.ok(10));
|
|
494
540
|
|
|
495
541
|
expect(Result.isErr(errorResult)).toBe(true);
|
|
@@ -510,6 +556,7 @@ describe('Result test', () => {
|
|
|
510
556
|
test('should work with pipe when curried', () => {
|
|
511
557
|
const parseNumber = (s: string): Result<number, string> => {
|
|
512
558
|
const n = Number(s);
|
|
559
|
+
|
|
513
560
|
return Number.isNaN(n) ? Result.err('Not a number') : Result.ok(n);
|
|
514
561
|
};
|
|
515
562
|
|
|
@@ -517,6 +564,7 @@ describe('Result test', () => {
|
|
|
517
564
|
n > 0 ? Result.ok(n * 2) : Result.err('Not positive');
|
|
518
565
|
|
|
519
566
|
const parser = Result.flatMap(parseNumber);
|
|
567
|
+
|
|
520
568
|
const doubler = Result.flatMap(doubleIfPositive);
|
|
521
569
|
|
|
522
570
|
const result = pipe(Result.ok('42')).map(parser).map(doubler).value;
|
|
@@ -532,17 +580,21 @@ describe('Result test', () => {
|
|
|
532
580
|
describe('swap', () => {
|
|
533
581
|
test('should swap Ok to Err', () => {
|
|
534
582
|
const okResult = Result.ok(42);
|
|
583
|
+
|
|
535
584
|
const swapped = Result.swap(okResult);
|
|
536
585
|
|
|
537
586
|
expect(Result.isErr(swapped)).toBe(true);
|
|
587
|
+
|
|
538
588
|
expect(Result.unwrapErr(swapped)).toBe(42);
|
|
539
589
|
});
|
|
540
590
|
|
|
541
591
|
test('should swap Err to Ok', () => {
|
|
542
592
|
const errResult = Result.err('error');
|
|
593
|
+
|
|
543
594
|
const swapped = Result.swap(errResult);
|
|
544
595
|
|
|
545
596
|
expect(Result.isOk(swapped)).toBe(true);
|
|
597
|
+
|
|
546
598
|
expect(Result.unwrapOk(swapped)).toBe('error');
|
|
547
599
|
});
|
|
548
600
|
});
|
|
@@ -550,14 +602,17 @@ describe('Result test', () => {
|
|
|
550
602
|
describe('toOptional', () => {
|
|
551
603
|
test('should convert Ok to Some-like', () => {
|
|
552
604
|
const okResult = Result.ok(42);
|
|
605
|
+
|
|
553
606
|
const optional = Result.toOptional(okResult);
|
|
554
607
|
|
|
555
608
|
expect(Optional.isSome(optional)).toBe(true);
|
|
609
|
+
|
|
556
610
|
expect(Optional.unwrapThrow(optional)).toBe(42);
|
|
557
611
|
});
|
|
558
612
|
|
|
559
613
|
test('should convert Err to None-like', () => {
|
|
560
614
|
const errResult = Result.err('error');
|
|
615
|
+
|
|
561
616
|
const optional = Result.toOptional(errResult);
|
|
562
617
|
|
|
563
618
|
expect(Optional.isNone(optional)).toBe(true);
|
|
@@ -591,6 +646,7 @@ describe('Result test', () => {
|
|
|
591
646
|
describe('unwrapErrOr', () => {
|
|
592
647
|
test('should return error value for Err result', () => {
|
|
593
648
|
const result = Result.err('error message');
|
|
649
|
+
|
|
594
650
|
const value = Result.unwrapErrOr(result, 'default');
|
|
595
651
|
|
|
596
652
|
expect(value).toBe('error message');
|
|
@@ -598,6 +654,7 @@ describe('Result test', () => {
|
|
|
598
654
|
|
|
599
655
|
test('should return default value for Ok result', () => {
|
|
600
656
|
const result = Result.ok(42);
|
|
657
|
+
|
|
601
658
|
const value = Result.unwrapErrOr(result, 'default');
|
|
602
659
|
|
|
603
660
|
expect(value).toBe('default');
|
|
@@ -607,11 +664,13 @@ describe('Result test', () => {
|
|
|
607
664
|
const unwrapErrorWithDefault = Result.unwrapErrOr('unknown error');
|
|
608
665
|
|
|
609
666
|
const errResult: Result<number, string> = Result.err('failed');
|
|
667
|
+
|
|
610
668
|
const errorValue = unwrapErrorWithDefault(errResult);
|
|
611
669
|
|
|
612
670
|
expect(errorValue).toBe('failed');
|
|
613
671
|
|
|
614
672
|
const okResult: Result<number, string> = Result.ok(42);
|
|
673
|
+
|
|
615
674
|
const defaultValue = unwrapErrorWithDefault(okResult);
|
|
616
675
|
|
|
617
676
|
expect(defaultValue).toBe('unknown error');
|
|
@@ -637,6 +696,7 @@ describe('Result test', () => {
|
|
|
637
696
|
describe('expectToBe', () => {
|
|
638
697
|
test('should return value for Ok result', () => {
|
|
639
698
|
const result = Result.ok(42);
|
|
699
|
+
|
|
640
700
|
const value = Result.expectToBe(result, 'Expected valid number');
|
|
641
701
|
|
|
642
702
|
expect(value).toBe(42);
|
|
@@ -654,6 +714,7 @@ describe('Result test', () => {
|
|
|
654
714
|
const mustBeOk = Result.expectToBe('Expected successful result');
|
|
655
715
|
|
|
656
716
|
const okResult = Result.ok('success');
|
|
717
|
+
|
|
657
718
|
const value = mustBeOk(okResult);
|
|
658
719
|
|
|
659
720
|
expect(value).toBe('success');
|
|
@@ -679,7 +740,9 @@ describe('Result test', () => {
|
|
|
679
740
|
describe('orElse', () => {
|
|
680
741
|
test('should return the first Result if it is Ok', () => {
|
|
681
742
|
const primary = Result.ok(42);
|
|
743
|
+
|
|
682
744
|
const fallback = Result.ok(100);
|
|
745
|
+
|
|
683
746
|
const result = Result.orElse(primary, fallback);
|
|
684
747
|
|
|
685
748
|
expect(Result.unwrapOk(result)).toBe(42);
|
|
@@ -687,7 +750,9 @@ describe('Result test', () => {
|
|
|
687
750
|
|
|
688
751
|
test('should return the alternative if the first is Err', () => {
|
|
689
752
|
const primary = Result.err('error');
|
|
753
|
+
|
|
690
754
|
const fallback = Result.ok('default');
|
|
755
|
+
|
|
691
756
|
const result = Result.orElse(primary, fallback);
|
|
692
757
|
|
|
693
758
|
expect(Result.unwrapOk(result)).toBe('default');
|
|
@@ -695,7 +760,9 @@ describe('Result test', () => {
|
|
|
695
760
|
|
|
696
761
|
test('should return Err if both are Err', () => {
|
|
697
762
|
const primary = Result.err('error1');
|
|
763
|
+
|
|
698
764
|
const fallback = Result.err('error2');
|
|
765
|
+
|
|
699
766
|
const result = Result.orElse(primary, fallback);
|
|
700
767
|
|
|
701
768
|
expect(Result.unwrapErr(result)).toBe('error2');
|
|
@@ -705,6 +772,7 @@ describe('Result test', () => {
|
|
|
705
772
|
const fallbackTo = Result.orElse(Result.ok('fallback'));
|
|
706
773
|
|
|
707
774
|
const okResult = Result.ok('primary');
|
|
775
|
+
|
|
708
776
|
const result = fallbackTo(okResult);
|
|
709
777
|
|
|
710
778
|
expect(Result.isOk(result)).toBe(true);
|
|
@@ -714,6 +782,7 @@ describe('Result test', () => {
|
|
|
714
782
|
}
|
|
715
783
|
|
|
716
784
|
const errResult: Result<string, string> = Result.err('failed');
|
|
785
|
+
|
|
717
786
|
const fallbackResult = fallbackTo(errResult);
|
|
718
787
|
|
|
719
788
|
expect(Result.isOk(fallbackResult)).toBe(true);
|
|
@@ -747,7 +816,9 @@ describe('Result test', () => {
|
|
|
747
816
|
describe('zip', () => {
|
|
748
817
|
test('should combine two Ok values into a tuple', () => {
|
|
749
818
|
const a = Result.ok(1);
|
|
819
|
+
|
|
750
820
|
const b = Result.ok('hello');
|
|
821
|
+
|
|
751
822
|
const zipped = Result.zip(a, b);
|
|
752
823
|
|
|
753
824
|
assert.deepStrictEqual(Result.unwrapOk(zipped), [1, 'hello']);
|
|
@@ -755,7 +826,9 @@ describe('Result test', () => {
|
|
|
755
826
|
|
|
756
827
|
test('should return first Err if first is Err', () => {
|
|
757
828
|
const a = Result.err('error1');
|
|
829
|
+
|
|
758
830
|
const b = Result.ok('hello');
|
|
831
|
+
|
|
759
832
|
const zipped = Result.zip(a, b);
|
|
760
833
|
|
|
761
834
|
expect(Result.unwrapErr(zipped)).toBe('error1');
|
|
@@ -763,7 +836,9 @@ describe('Result test', () => {
|
|
|
763
836
|
|
|
764
837
|
test('should return second Err if second is Err', () => {
|
|
765
838
|
const a = Result.ok(1);
|
|
839
|
+
|
|
766
840
|
const b = Result.err('error2');
|
|
841
|
+
|
|
767
842
|
const zipped = Result.zip(a, b);
|
|
768
843
|
|
|
769
844
|
expect(Result.unwrapErr(zipped)).toBe('error2');
|
|
@@ -771,7 +846,9 @@ describe('Result test', () => {
|
|
|
771
846
|
|
|
772
847
|
test('should return first Err if both are Err', () => {
|
|
773
848
|
const a = Result.err('error1');
|
|
849
|
+
|
|
774
850
|
const b = Result.err('error2');
|
|
851
|
+
|
|
775
852
|
const zipped = Result.zip(a, b);
|
|
776
853
|
|
|
777
854
|
expect(Result.unwrapErr(zipped)).toBe('error1');
|
|
@@ -783,6 +860,7 @@ describe('Result test', () => {
|
|
|
783
860
|
const result = Result.fromThrowable(() => 42);
|
|
784
861
|
|
|
785
862
|
expect(Result.isOk(result)).toBe(true);
|
|
863
|
+
|
|
786
864
|
expect(Result.unwrapOk(result)).toBe(42);
|
|
787
865
|
|
|
788
866
|
expectType<typeof result, Result<number, Error>>('<=');
|
|
@@ -790,6 +868,7 @@ describe('Result test', () => {
|
|
|
790
868
|
|
|
791
869
|
test('should return Ok with object when function succeeds', () => {
|
|
792
870
|
const obj = { name: 'test', value: 123 };
|
|
871
|
+
|
|
793
872
|
const result = Result.fromThrowable(() => obj);
|
|
794
873
|
|
|
795
874
|
expect(Result.isOk(result)).toBe(true);
|
|
@@ -799,6 +878,7 @@ describe('Result test', () => {
|
|
|
799
878
|
|
|
800
879
|
test('should return Err when function throws Error', () => {
|
|
801
880
|
const errorMessage = 'Something went wrong';
|
|
881
|
+
|
|
802
882
|
const result = Result.fromThrowable(() => {
|
|
803
883
|
throw new Error(errorMessage);
|
|
804
884
|
});
|
|
@@ -809,12 +889,14 @@ describe('Result test', () => {
|
|
|
809
889
|
const error = result.value;
|
|
810
890
|
|
|
811
891
|
expect(error).toBeInstanceOf(Error);
|
|
892
|
+
|
|
812
893
|
expect(error.message).toBe(errorMessage);
|
|
813
894
|
}
|
|
814
895
|
});
|
|
815
896
|
|
|
816
897
|
test('should return Err when function throws string', () => {
|
|
817
898
|
const errorMessage = 'String error';
|
|
899
|
+
|
|
818
900
|
const result = Result.fromThrowable(() => {
|
|
819
901
|
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
820
902
|
throw errorMessage;
|
|
@@ -826,6 +908,7 @@ describe('Result test', () => {
|
|
|
826
908
|
const error = result.value;
|
|
827
909
|
|
|
828
910
|
expect(error).toBeInstanceOf(Error);
|
|
911
|
+
|
|
829
912
|
expect(error.message).toBe(errorMessage);
|
|
830
913
|
}
|
|
831
914
|
});
|
|
@@ -842,12 +925,14 @@ describe('Result test', () => {
|
|
|
842
925
|
const error = result.value;
|
|
843
926
|
|
|
844
927
|
expect(error).toBeInstanceOf(Error);
|
|
928
|
+
|
|
845
929
|
expect(error.message).toBe('404');
|
|
846
930
|
}
|
|
847
931
|
});
|
|
848
932
|
|
|
849
933
|
test('should work with JSON.parse', () => {
|
|
850
934
|
const validJson = '{"key": "value"}';
|
|
935
|
+
|
|
851
936
|
const invalidJson = '{invalid json}';
|
|
852
937
|
|
|
853
938
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
@@ -875,10 +960,13 @@ describe('Result test', () => {
|
|
|
875
960
|
// This won't throw, but demonstrates the pattern
|
|
876
961
|
const result = Result.fromThrowable(() => {
|
|
877
962
|
const index = 5;
|
|
963
|
+
|
|
878
964
|
const value = arr[index];
|
|
965
|
+
|
|
879
966
|
if (value === undefined) {
|
|
880
967
|
throw new Error('Index out of bounds');
|
|
881
968
|
}
|
|
969
|
+
|
|
882
970
|
return value;
|
|
883
971
|
});
|
|
884
972
|
|
|
@@ -9,10 +9,11 @@ import { ErrTypeTagName } from './tag.mjs';
|
|
|
9
9
|
* const failure = TernaryResult.err(new Error('missing data'));
|
|
10
10
|
*
|
|
11
11
|
* assert.strictEqual(failure.$$tag, 'ts-data-forge::Result.err');
|
|
12
|
+
*
|
|
12
13
|
* assert.ok(TernaryResult.isErr(failure));
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
|
-
export const err = <E,>(value: E): TernaryErr<E> => ({
|
|
16
|
+
export const err = <const E,>(value: E): TernaryErr<E> => ({
|
|
16
17
|
$$tag: ErrTypeTagName,
|
|
17
18
|
value,
|
|
18
19
|
});
|
|
@@ -11,6 +11,7 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
11
11
|
* const okValue = TernaryResult.ok('ready');
|
|
12
12
|
*
|
|
13
13
|
* assert.strictEqual(TernaryResult.expectToBe(okValue, 'missing'), 'ready');
|
|
14
|
+
*
|
|
14
15
|
* const expectResult = TernaryResult.expectToBe<string>('needs value');
|
|
15
16
|
*
|
|
16
17
|
* assert.throws(() => expectResult(TernaryResult.err('oops')), /needs value/u);
|
|
@@ -32,10 +33,13 @@ export function expectToBe<R extends UnknownTernaryResult>(
|
|
|
32
33
|
switch (args.length) {
|
|
33
34
|
case 2: {
|
|
34
35
|
const [result, message] = args;
|
|
36
|
+
|
|
35
37
|
return expectImpl(result, message);
|
|
36
38
|
}
|
|
39
|
+
|
|
37
40
|
case 1: {
|
|
38
41
|
const [message] = args;
|
|
42
|
+
|
|
39
43
|
return (result: R) => expectImpl(result, message);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -17,14 +17,18 @@ import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
|
17
17
|
* const doubled = TernaryResult.flatMap(TernaryResult.ok('3'), (text) =>
|
|
18
18
|
* TernaryResult.map(parse(text), (num) => num * 2),
|
|
19
19
|
* );
|
|
20
|
+
*
|
|
20
21
|
* const warnPassthrough = TernaryResult.flatMap(
|
|
21
22
|
* TernaryResult.warn('3', 'retry'),
|
|
22
23
|
* parse,
|
|
23
24
|
* );
|
|
25
|
+
*
|
|
24
26
|
* const errPassthrough = TernaryResult.flatMap(TernaryResult.err('oops'), parse);
|
|
25
27
|
*
|
|
26
28
|
* assert.deepStrictEqual(doubled, TernaryResult.ok(6));
|
|
29
|
+
*
|
|
27
30
|
* assert.deepStrictEqual(warnPassthrough, TernaryResult.warn(3, 'retry'));
|
|
31
|
+
*
|
|
28
32
|
* assert.deepStrictEqual(errPassthrough, TernaryResult.err('oops'));
|
|
29
33
|
* ```
|
|
30
34
|
*/
|
|
@@ -51,10 +55,13 @@ export function flatMap<R extends UnknownTernaryResult, S2, W2, E2>(
|
|
|
51
55
|
switch (args.length) {
|
|
52
56
|
case 2: {
|
|
53
57
|
const [result, flatMapFn] = args;
|
|
58
|
+
|
|
54
59
|
return flatMapImpl(result, flatMapFn);
|
|
55
60
|
}
|
|
61
|
+
|
|
56
62
|
case 1: {
|
|
57
63
|
const [flatMapFn] = args;
|
|
64
|
+
|
|
58
65
|
return (result: R) => flatMapImpl(result, flatMapFn);
|
|
59
66
|
}
|
|
60
67
|
}
|
|
@@ -17,6 +17,7 @@ import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
|
17
17
|
* (warn: string) => warn.length,
|
|
18
18
|
* (error: string) => error.toUpperCase(),
|
|
19
19
|
* );
|
|
20
|
+
*
|
|
20
21
|
* const warnFold = TernaryResult.fold(
|
|
21
22
|
* TernaryResult.warn(2, 'spike'),
|
|
22
23
|
* (value: number) => value,
|
|
@@ -25,6 +26,7 @@ import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
|
25
26
|
* );
|
|
26
27
|
*
|
|
27
28
|
* assert.deepStrictEqual(okFold, TernaryResult.ok(4));
|
|
29
|
+
*
|
|
28
30
|
* assert.deepStrictEqual(warnFold, TernaryResult.warn(2, 'SPIKE'));
|
|
29
31
|
* ```
|
|
30
32
|
*/
|
|
@@ -59,10 +61,13 @@ export function fold<R extends UnknownTernaryResult, S2, W2, E2>(
|
|
|
59
61
|
switch (args.length) {
|
|
60
62
|
case 4: {
|
|
61
63
|
const [result, mapOk, mapWarn, mapErr] = args;
|
|
64
|
+
|
|
62
65
|
return foldImpl(result, mapOk, mapWarn, mapErr);
|
|
63
66
|
}
|
|
67
|
+
|
|
64
68
|
case 3: {
|
|
65
69
|
const [mapOk, mapWarn, mapErr] = args;
|
|
70
|
+
|
|
66
71
|
return (result: R) => foldImpl(result, mapOk, mapWarn, mapErr);
|
|
67
72
|
}
|
|
68
73
|
}
|
|
@@ -12,11 +12,13 @@ type UnwrapPromise<P extends Promise<unknown>> =
|
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
14
|
* const resolved = await TernaryResult.fromPromise(Promise.resolve('ok'));
|
|
15
|
+
*
|
|
15
16
|
* const rejected = await TernaryResult.fromPromise(
|
|
16
17
|
* Promise.reject(new Error('fail')),
|
|
17
18
|
* );
|
|
18
19
|
*
|
|
19
20
|
* assert.deepStrictEqual(resolved, TernaryResult.ok('ok'));
|
|
21
|
+
*
|
|
20
22
|
* assert.ok(TernaryResult.isErr(rejected));
|
|
21
23
|
* ```
|
|
22
24
|
*/
|