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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isError } from '@sindresorhus/is';
|
|
1
2
|
import { unknownToString } from '../../../others/index.mjs';
|
|
2
3
|
import { err } from './ternary-result-err.mjs';
|
|
3
4
|
import { ok } from './ternary-result-ok.mjs';
|
|
@@ -9,11 +10,13 @@ import { ok } from './ternary-result-ok.mjs';
|
|
|
9
10
|
*
|
|
10
11
|
* ```ts
|
|
11
12
|
* const success = TernaryResult.fromThrowable(() => 1 + 1);
|
|
13
|
+
*
|
|
12
14
|
* const failure = TernaryResult.fromThrowable(() => {
|
|
13
15
|
* throw new Error('boom');
|
|
14
16
|
* });
|
|
15
17
|
*
|
|
16
18
|
* assert.deepStrictEqual(success, TernaryResult.ok(2));
|
|
19
|
+
*
|
|
17
20
|
* assert.ok(TernaryResult.isErr(failure));
|
|
18
21
|
* ```
|
|
19
22
|
*/
|
|
@@ -23,9 +26,10 @@ export const fromThrowable = <T,>(
|
|
|
23
26
|
try {
|
|
24
27
|
return ok(fn());
|
|
25
28
|
} catch (error) {
|
|
26
|
-
if (
|
|
29
|
+
if (isError(error)) {
|
|
27
30
|
return err(error);
|
|
28
31
|
}
|
|
32
|
+
|
|
29
33
|
return err(new Error(unknownToString(error)));
|
|
30
34
|
}
|
|
31
35
|
};
|
|
@@ -8,11 +8,15 @@ import { ErrTypeTagName, OkTypeTagName, WarnTypeTagName } from './tag.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const okValue = TernaryResult.ok('done');
|
|
11
|
+
*
|
|
11
12
|
* const warnValue = TernaryResult.warn('done', 'retry later');
|
|
13
|
+
*
|
|
12
14
|
* const notResult = { $$tag: 'ts-data-forge::Result.ok' };
|
|
13
15
|
*
|
|
14
16
|
* assert.ok(TernaryResult.isTernaryResult(okValue));
|
|
17
|
+
*
|
|
15
18
|
* assert.ok(TernaryResult.isTernaryResult(warnValue));
|
|
19
|
+
*
|
|
16
20
|
* assert.ok(!TernaryResult.isTernaryResult(notResult));
|
|
17
21
|
* ```
|
|
18
22
|
*/
|
|
@@ -9,15 +9,18 @@ import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
11
|
* const errValue = TernaryResult.err('boom');
|
|
12
|
+
*
|
|
12
13
|
* const mappedErr = TernaryResult.mapErr(errValue, (error) =>
|
|
13
14
|
* error.toUpperCase(),
|
|
14
15
|
* );
|
|
16
|
+
*
|
|
15
17
|
* const warnPassthrough = TernaryResult.mapErr(
|
|
16
18
|
* TernaryResult.warn(2, 'slow'),
|
|
17
19
|
* (error: string) => `${error}!`,
|
|
18
20
|
* );
|
|
19
21
|
*
|
|
20
22
|
* assert.deepStrictEqual(mappedErr, TernaryResult.err('BOOM'));
|
|
23
|
+
*
|
|
21
24
|
* assert.deepStrictEqual(warnPassthrough, TernaryResult.warn(2, 'slow'));
|
|
22
25
|
* ```
|
|
23
26
|
*/
|
|
@@ -41,10 +44,13 @@ export function mapErr<R extends UnknownTernaryResult, E2>(
|
|
|
41
44
|
switch (args.length) {
|
|
42
45
|
case 2: {
|
|
43
46
|
const [result, mapFn] = args;
|
|
47
|
+
|
|
44
48
|
return mapErrImpl(result, mapFn);
|
|
45
49
|
}
|
|
50
|
+
|
|
46
51
|
case 1: {
|
|
47
52
|
const [mapFn] = args;
|
|
53
|
+
|
|
48
54
|
return (result: R) => mapErrImpl(result, mapFn);
|
|
49
55
|
}
|
|
50
56
|
}
|
|
@@ -9,13 +9,16 @@ import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
11
|
* const warnValue = TernaryResult.warn(2, 'slow');
|
|
12
|
+
*
|
|
12
13
|
* const mappedWarn = TernaryResult.mapWarn(warnValue, (warning) => `${warning}!`);
|
|
14
|
+
*
|
|
13
15
|
* const okPassthrough = TernaryResult.mapWarn(
|
|
14
16
|
* TernaryResult.ok(3),
|
|
15
17
|
* (value: number) => value * 2,
|
|
16
18
|
* );
|
|
17
19
|
*
|
|
18
20
|
* assert.deepStrictEqual(mappedWarn, TernaryResult.warn(2, 'slow!'));
|
|
21
|
+
*
|
|
19
22
|
* assert.deepStrictEqual(okPassthrough, TernaryResult.ok(3));
|
|
20
23
|
* ```
|
|
21
24
|
*/
|
|
@@ -39,10 +42,13 @@ export function mapWarn<R extends UnknownTernaryResult, W2>(
|
|
|
39
42
|
switch (args.length) {
|
|
40
43
|
case 2: {
|
|
41
44
|
const [result, mapFn] = args;
|
|
45
|
+
|
|
42
46
|
return mapWarnImpl(result, mapFn);
|
|
43
47
|
}
|
|
48
|
+
|
|
44
49
|
case 1: {
|
|
45
50
|
const [mapFn] = args;
|
|
51
|
+
|
|
46
52
|
return (result: R) => mapWarnImpl(result, mapFn);
|
|
47
53
|
}
|
|
48
54
|
}
|
|
@@ -11,21 +11,27 @@ import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* ```ts
|
|
13
13
|
* const okNumber = TernaryResult.ok(5);
|
|
14
|
+
*
|
|
14
15
|
* const warnValue = TernaryResult.warn(5, 'slow');
|
|
16
|
+
*
|
|
15
17
|
* const errValue = TernaryResult.err('bad');
|
|
16
18
|
*
|
|
17
19
|
* const doubled = TernaryResult.map(okNumber, (value) => value * 2);
|
|
20
|
+
*
|
|
18
21
|
* const warnPassthrough = TernaryResult.map(
|
|
19
22
|
* warnValue,
|
|
20
23
|
* (value: number) => value * 2,
|
|
21
24
|
* );
|
|
25
|
+
*
|
|
22
26
|
* const errPassthrough = TernaryResult.map(
|
|
23
27
|
* errValue,
|
|
24
28
|
* (value: number) => value * 2,
|
|
25
29
|
* );
|
|
26
30
|
*
|
|
27
31
|
* assert.deepStrictEqual(doubled, TernaryResult.ok(10));
|
|
32
|
+
*
|
|
28
33
|
* assert.deepStrictEqual(warnPassthrough, TernaryResult.warn(10, 'slow'));
|
|
34
|
+
*
|
|
29
35
|
* assert.deepStrictEqual(errPassthrough, errValue);
|
|
30
36
|
* ```
|
|
31
37
|
*/
|
|
@@ -49,10 +55,13 @@ export function map<R extends UnknownTernaryResult, S2>(
|
|
|
49
55
|
switch (args.length) {
|
|
50
56
|
case 2: {
|
|
51
57
|
const [result, mapFn] = args;
|
|
58
|
+
|
|
52
59
|
return mapImpl(result, mapFn);
|
|
53
60
|
}
|
|
61
|
+
|
|
54
62
|
case 1: {
|
|
55
63
|
const [mapFn] = args;
|
|
64
|
+
|
|
56
65
|
return (result: R) => mapImpl(result, mapFn);
|
|
57
66
|
}
|
|
58
67
|
}
|
|
@@ -14,10 +14,12 @@ import { type NarrowToOk, type NarrowToWarn } from './types.mjs';
|
|
|
14
14
|
* TernaryResult.orElse(TernaryResult.ok('value'), fallback),
|
|
15
15
|
* TernaryResult.ok('value'),
|
|
16
16
|
* );
|
|
17
|
+
*
|
|
17
18
|
* assert.deepStrictEqual(
|
|
18
19
|
* TernaryResult.orElse(TernaryResult.warn('value', 'warn'), fallback),
|
|
19
20
|
* TernaryResult.warn('value', 'warn'),
|
|
20
21
|
* );
|
|
22
|
+
*
|
|
21
23
|
* assert.deepStrictEqual(
|
|
22
24
|
* TernaryResult.orElse(TernaryResult.err('err'), fallback),
|
|
23
25
|
* fallback,
|
|
@@ -47,10 +49,13 @@ export function orElse<
|
|
|
47
49
|
switch (args.length) {
|
|
48
50
|
case 2: {
|
|
49
51
|
const [result, alternative] = args;
|
|
52
|
+
|
|
50
53
|
return orElseImpl(result, alternative);
|
|
51
54
|
}
|
|
55
|
+
|
|
52
56
|
case 1: {
|
|
53
57
|
const [alternative] = args;
|
|
58
|
+
|
|
54
59
|
return (result: R) => orElseImpl(result, alternative);
|
|
55
60
|
}
|
|
56
61
|
}
|
|
@@ -10,9 +10,11 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
10
10
|
*
|
|
11
11
|
* ```ts
|
|
12
12
|
* const okValue = TernaryResult.ok(7);
|
|
13
|
+
*
|
|
13
14
|
* const warnValue = TernaryResult.warn(7, 'warn');
|
|
14
15
|
*
|
|
15
16
|
* assert.deepStrictEqual(TernaryResult.toOptional(okValue), Optional.some(7));
|
|
17
|
+
*
|
|
16
18
|
* assert.deepStrictEqual(TernaryResult.toOptional(warnValue), Optional.some(7));
|
|
17
19
|
* ```
|
|
18
20
|
*/
|
|
@@ -10,9 +10,11 @@ import { type UnwrapErr } from './types.mjs';
|
|
|
10
10
|
* const okValue = TernaryResult.ok('value');
|
|
11
11
|
*
|
|
12
12
|
* assert.strictEqual(TernaryResult.unwrapErrOr(okValue, 'default'), 'default');
|
|
13
|
+
*
|
|
13
14
|
* const unwrapErr = TernaryResult.unwrapErrOr('fallback error');
|
|
14
15
|
*
|
|
15
16
|
* assert.strictEqual(unwrapErr(TernaryResult.err('boom')), 'boom');
|
|
17
|
+
*
|
|
16
18
|
* assert.strictEqual(
|
|
17
19
|
* unwrapErr(TernaryResult.warn('value', 'warn')),
|
|
18
20
|
* 'fallback error',
|
|
@@ -35,10 +37,13 @@ export function unwrapErrOr<R extends UnknownTernaryResult, D>(
|
|
|
35
37
|
switch (args.length) {
|
|
36
38
|
case 2: {
|
|
37
39
|
const [result, defaultValue] = args;
|
|
40
|
+
|
|
38
41
|
return unwrapErr(result) ?? defaultValue;
|
|
39
42
|
}
|
|
43
|
+
|
|
40
44
|
case 1: {
|
|
41
45
|
const [defaultValue] = args;
|
|
46
|
+
|
|
42
47
|
return (result: R) => unwrapErr(result) ?? defaultValue;
|
|
43
48
|
}
|
|
44
49
|
}
|
|
@@ -13,6 +13,7 @@ import { variantName } from './variant-name.mjs';
|
|
|
13
13
|
* const errValue = TernaryResult.err('boom');
|
|
14
14
|
*
|
|
15
15
|
* assert.strictEqual(TernaryResult.unwrapErrThrow(errValue), 'boom');
|
|
16
|
+
*
|
|
16
17
|
* assert.throws(
|
|
17
18
|
* () => TernaryResult.unwrapErrThrow(TernaryResult.ok('value')),
|
|
18
19
|
* /Expected Err/u,
|
|
@@ -8,9 +8,11 @@ import { type UnwrapErr } from './types.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const errValue = TernaryResult.err('fail');
|
|
11
|
+
*
|
|
11
12
|
* const okValue = TernaryResult.ok('value');
|
|
12
13
|
*
|
|
13
14
|
* assert.strictEqual(TernaryResult.unwrapErr(errValue), 'fail');
|
|
15
|
+
*
|
|
14
16
|
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
15
17
|
* assert.strictEqual(TernaryResult.unwrapErr(okValue), undefined);
|
|
16
18
|
* ```
|
|
@@ -10,9 +10,11 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
10
10
|
* const errValue = TernaryResult.err('err');
|
|
11
11
|
*
|
|
12
12
|
* assert.strictEqual(TernaryResult.unwrapOkOr(errValue, 0), 0);
|
|
13
|
+
*
|
|
13
14
|
* const unwrapWithDefault = TernaryResult.unwrapOkOr('fallback');
|
|
14
15
|
*
|
|
15
16
|
* assert.strictEqual(unwrapWithDefault(TernaryResult.ok(5)), 5);
|
|
17
|
+
*
|
|
16
18
|
* assert.strictEqual(
|
|
17
19
|
* unwrapWithDefault(TernaryResult.warn('warn-value', 'warn')),
|
|
18
20
|
* 'warn-value',
|
|
@@ -35,10 +37,13 @@ export function unwrapOkOr<R extends UnknownTernaryResult, D>(
|
|
|
35
37
|
switch (args.length) {
|
|
36
38
|
case 2: {
|
|
37
39
|
const [result, defaultValue] = args;
|
|
40
|
+
|
|
38
41
|
return unwrapOk(result) ?? defaultValue;
|
|
39
42
|
}
|
|
43
|
+
|
|
40
44
|
case 1: {
|
|
41
45
|
const [defaultValue] = args;
|
|
46
|
+
|
|
42
47
|
return (result: R) => unwrapOk(result) ?? defaultValue;
|
|
43
48
|
}
|
|
44
49
|
}
|
|
@@ -9,13 +9,16 @@ import { type UnwrapOk } from './types.mjs';
|
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
11
|
* const okValue = TernaryResult.ok(3);
|
|
12
|
+
*
|
|
12
13
|
* const warnValue = TernaryResult.warn(4, 'warn');
|
|
13
14
|
*
|
|
14
15
|
* assert.strictEqual(TernaryResult.unwrapOk(okValue), 3);
|
|
16
|
+
*
|
|
15
17
|
* assert.strictEqual(TernaryResult.unwrapOk(warnValue), 4);
|
|
16
18
|
* ```
|
|
17
19
|
*/
|
|
18
20
|
export function unwrapOk<R extends TernaryOk<unknown>>(result: R): UnwrapOk<R>;
|
|
21
|
+
|
|
19
22
|
export function unwrapOk<R extends UnknownTernaryResult>(
|
|
20
23
|
result: R,
|
|
21
24
|
): UnwrapOk<R> | undefined;
|
|
@@ -12,6 +12,7 @@ import { type UnwrapErr, type UnwrapOk, type UnwrapWarn } from './types.mjs';
|
|
|
12
12
|
* const okValue = TernaryResult.ok('ready');
|
|
13
13
|
*
|
|
14
14
|
* assert.strictEqual(TernaryResult.unwrapThrow(okValue), 'ready');
|
|
15
|
+
*
|
|
15
16
|
* assert.throws(
|
|
16
17
|
* () => TernaryResult.unwrapThrow(TernaryResult.warn('warn', 'warned')),
|
|
17
18
|
* /Expected Ok/u,
|
|
@@ -10,9 +10,11 @@ import { type UnwrapWarn } from './types.mjs';
|
|
|
10
10
|
* const okValue = TernaryResult.ok('value');
|
|
11
11
|
*
|
|
12
12
|
* assert.strictEqual(TernaryResult.unwrapWarnOr(okValue, 'warn'), 'warn');
|
|
13
|
+
*
|
|
13
14
|
* const unwrapWarn = TernaryResult.unwrapWarnOr('fallback warn');
|
|
14
15
|
*
|
|
15
16
|
* assert.strictEqual(unwrapWarn(TernaryResult.warn('value', 'slow')), 'slow');
|
|
17
|
+
*
|
|
16
18
|
* assert.strictEqual(unwrapWarn(TernaryResult.err('err')), 'fallback warn');
|
|
17
19
|
* ```
|
|
18
20
|
*/
|
|
@@ -32,10 +34,13 @@ export function unwrapWarnOr<R extends UnknownTernaryResult, D>(
|
|
|
32
34
|
switch (args.length) {
|
|
33
35
|
case 2: {
|
|
34
36
|
const [result, defaultValue] = args;
|
|
37
|
+
|
|
35
38
|
return unwrapWarn(result) ?? defaultValue;
|
|
36
39
|
}
|
|
40
|
+
|
|
37
41
|
case 1: {
|
|
38
42
|
const [defaultValue] = args;
|
|
43
|
+
|
|
39
44
|
return (result: R) => unwrapWarn(result) ?? defaultValue;
|
|
40
45
|
}
|
|
41
46
|
}
|
|
@@ -12,6 +12,7 @@ import { variantName } from './variant-name.mjs';
|
|
|
12
12
|
* const warnValue = TernaryResult.warn('pending', 'check logs');
|
|
13
13
|
*
|
|
14
14
|
* assert.strictEqual(TernaryResult.unwrapWarnThrow(warnValue), 'check logs');
|
|
15
|
+
*
|
|
15
16
|
* assert.throws(
|
|
16
17
|
* () => TernaryResult.unwrapWarnThrow(TernaryResult.err('err')),
|
|
17
18
|
* /Expected Warn/u,
|
|
@@ -8,9 +8,11 @@ import { type UnwrapWarn } from './types.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const warnValue = TernaryResult.warn('ok', 'careful');
|
|
11
|
+
*
|
|
11
12
|
* const okValue = TernaryResult.ok('ok');
|
|
12
13
|
*
|
|
13
14
|
* assert.strictEqual(TernaryResult.unwrapWarn(warnValue), 'careful');
|
|
15
|
+
*
|
|
14
16
|
* // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
15
17
|
* assert.strictEqual(TernaryResult.unwrapWarn(okValue), undefined);
|
|
16
18
|
* ```
|
|
@@ -16,7 +16,10 @@ import { WarnTypeTagName } from './tag.mjs';
|
|
|
16
16
|
* });
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
export const warn = <
|
|
19
|
+
export const warn = <const S, const W>(
|
|
20
|
+
value: S,
|
|
21
|
+
warning: W,
|
|
22
|
+
): TernaryWarn<S, W> => ({
|
|
20
23
|
$$tag: WarnTypeTagName,
|
|
21
24
|
value,
|
|
22
25
|
warning,
|
|
@@ -10,20 +10,24 @@ import { warn } from './ternary-result-warn.mjs';
|
|
|
10
10
|
*
|
|
11
11
|
* ```ts
|
|
12
12
|
* const okPair = TernaryResult.zip(TernaryResult.ok('left'), TernaryResult.ok(1));
|
|
13
|
+
*
|
|
13
14
|
* const warnPair = TernaryResult.zip(
|
|
14
15
|
* TernaryResult.warn('left', 'warn'),
|
|
15
16
|
* TernaryResult.ok(1),
|
|
16
17
|
* );
|
|
18
|
+
*
|
|
17
19
|
* const errPair = TernaryResult.zip(
|
|
18
20
|
* TernaryResult.ok('left'),
|
|
19
21
|
* TernaryResult.err('err'),
|
|
20
22
|
* );
|
|
21
23
|
*
|
|
22
24
|
* assert.deepStrictEqual(okPair, TernaryResult.ok(['left', 1] as const));
|
|
25
|
+
*
|
|
23
26
|
* assert.deepStrictEqual(
|
|
24
27
|
* warnPair,
|
|
25
28
|
* TernaryResult.warn(['left', 1] as const, 'warn'),
|
|
26
29
|
* );
|
|
30
|
+
*
|
|
27
31
|
* assert.deepStrictEqual(errPair, TernaryResult.err('err'));
|
|
28
32
|
* ```
|
|
29
33
|
*/
|
|
@@ -5,47 +5,65 @@ import { TernaryResult } from './ternary-result/index.mjs';
|
|
|
5
5
|
describe('TernaryResult test', () => {
|
|
6
6
|
test('constructors and guards', () => {
|
|
7
7
|
const ok = TernaryResult.ok(1);
|
|
8
|
+
|
|
8
9
|
const warn = TernaryResult.warn(1, 'caution');
|
|
10
|
+
|
|
9
11
|
const err = TernaryResult.err(new Error('boom'));
|
|
10
12
|
|
|
11
13
|
expect(TernaryResult.isOk(ok)).toBe(true);
|
|
14
|
+
|
|
12
15
|
expect(TernaryResult.isWarn(warn)).toBe(true);
|
|
16
|
+
|
|
13
17
|
expect(TernaryResult.isErr(err)).toBe(true);
|
|
18
|
+
|
|
14
19
|
expect(TernaryResult.isTernaryResult(ok)).toBe(true);
|
|
20
|
+
|
|
15
21
|
expect(TernaryResult.isTernaryResult({})).toBe(false);
|
|
16
22
|
|
|
17
23
|
expectType<typeof ok, TernaryResult<number, never, never>>('<=');
|
|
24
|
+
|
|
18
25
|
expectType<typeof warn, TernaryResult<number, never, string>>('<=');
|
|
26
|
+
|
|
19
27
|
expectType<typeof err, TernaryResult<never, Error, never>>('<=');
|
|
20
28
|
});
|
|
21
29
|
|
|
22
30
|
test('map transforms Ok and Warn success values', () => {
|
|
23
31
|
const ok = TernaryResult.ok(2);
|
|
32
|
+
|
|
24
33
|
const warn = TernaryResult.warn(2, 'check');
|
|
34
|
+
|
|
25
35
|
const err = TernaryResult.err('fail');
|
|
26
36
|
|
|
27
37
|
const double = TernaryResult.map((value: number) => value * 2);
|
|
28
38
|
|
|
29
39
|
expect(TernaryResult.unwrapOk(double(ok))).toBe(4);
|
|
40
|
+
|
|
30
41
|
expect(TernaryResult.unwrapOk(double(warn))).toBe(4);
|
|
42
|
+
|
|
31
43
|
expect(TernaryResult.unwrapWarn(double(warn))).toBe('check');
|
|
44
|
+
|
|
32
45
|
expect(TernaryResult.unwrapErr(double(err))).toBe('fail');
|
|
33
46
|
});
|
|
34
47
|
|
|
35
48
|
test('mapWarn and mapErr leave other variants untouched', () => {
|
|
36
49
|
const warn = TernaryResult.warn(2, 'slow');
|
|
50
|
+
|
|
37
51
|
const err = TernaryResult.err('err');
|
|
38
52
|
|
|
39
53
|
const warnMessage = TernaryResult.mapWarn(
|
|
40
54
|
(warning: string) => `${warning}!`,
|
|
41
55
|
);
|
|
56
|
+
|
|
42
57
|
const errUpper = TernaryResult.mapErr((value: string) =>
|
|
43
58
|
value.toUpperCase(),
|
|
44
59
|
);
|
|
45
60
|
|
|
46
61
|
expect(TernaryResult.unwrapWarn(warnMessage(warn))).toBe('slow!');
|
|
62
|
+
|
|
47
63
|
expect(TernaryResult.unwrapOk(warnMessage(warn))).toBe(2);
|
|
64
|
+
|
|
48
65
|
expect(TernaryResult.unwrapWarn(errUpper(warn))).toBe('slow');
|
|
66
|
+
|
|
49
67
|
expect(TernaryResult.unwrapErr(errUpper(err))).toBe('ERR');
|
|
50
68
|
});
|
|
51
69
|
|
|
@@ -56,17 +74,22 @@ describe('TernaryResult test', () => {
|
|
|
56
74
|
: TernaryResult.ok(Number(value));
|
|
57
75
|
|
|
58
76
|
const warn = TernaryResult.warn('3', 'slow');
|
|
77
|
+
|
|
59
78
|
const err = TernaryResult.err('bad');
|
|
60
79
|
|
|
61
80
|
const okResult = TernaryResult.flatMap(TernaryResult.ok('3'), parse);
|
|
81
|
+
|
|
62
82
|
const warnResult = TernaryResult.flatMap(warn, parse);
|
|
83
|
+
|
|
63
84
|
const errResult = TernaryResult.flatMap(err, parse);
|
|
64
85
|
|
|
65
86
|
expect(TernaryResult.unwrapOk(okResult)).toBe(3);
|
|
87
|
+
|
|
66
88
|
expect(TernaryResult.isWarn(warnResult)).toBe(true);
|
|
67
89
|
|
|
68
90
|
if (TernaryResult.isWarn(warnResult)) {
|
|
69
91
|
expect(warnResult.value).toBe(3);
|
|
92
|
+
|
|
70
93
|
expect(warnResult.warning).toBe('slow');
|
|
71
94
|
}
|
|
72
95
|
|
|
@@ -80,12 +103,14 @@ describe('TernaryResult test', () => {
|
|
|
80
103
|
(w: string) => ({ warning: w }),
|
|
81
104
|
(e: string) => ({ message: e }),
|
|
82
105
|
);
|
|
106
|
+
|
|
83
107
|
const warn = TernaryResult.fold(
|
|
84
108
|
TernaryResult.warn(2, 'heads up'),
|
|
85
109
|
(x) => x * 2,
|
|
86
110
|
(w: string) => ({ warning: w }),
|
|
87
111
|
(e: string) => ({ message: e }),
|
|
88
112
|
);
|
|
113
|
+
|
|
89
114
|
const err = TernaryResult.fold(
|
|
90
115
|
TernaryResult.err('boom'),
|
|
91
116
|
(x) => x,
|
|
@@ -94,11 +119,13 @@ describe('TernaryResult test', () => {
|
|
|
94
119
|
);
|
|
95
120
|
|
|
96
121
|
expect(TernaryResult.unwrapOk(value)).toBe(2);
|
|
122
|
+
|
|
97
123
|
expect(TernaryResult.unwrapOk(warn)).toBe(4);
|
|
98
124
|
|
|
99
125
|
assert.deepStrictEqual(TernaryResult.unwrapWarn(warn), {
|
|
100
126
|
warning: 'heads up',
|
|
101
127
|
});
|
|
128
|
+
|
|
102
129
|
assert.deepStrictEqual(TernaryResult.unwrapErr(err), { message: 'boom' });
|
|
103
130
|
});
|
|
104
131
|
|
|
@@ -109,10 +136,12 @@ describe('TernaryResult test', () => {
|
|
|
109
136
|
TernaryResult.orElse(TernaryResult.ok('value'), fallback),
|
|
110
137
|
TernaryResult.ok('value'),
|
|
111
138
|
);
|
|
139
|
+
|
|
112
140
|
assert.deepStrictEqual(
|
|
113
141
|
TernaryResult.orElse(TernaryResult.warn('value', 'warn'), fallback),
|
|
114
142
|
TernaryResult.warn('value', 'warn'),
|
|
115
143
|
);
|
|
144
|
+
|
|
116
145
|
assert.deepStrictEqual(
|
|
117
146
|
TernaryResult.orElse(TernaryResult.err('err'), fallback),
|
|
118
147
|
fallback,
|
|
@@ -121,14 +150,21 @@ describe('TernaryResult test', () => {
|
|
|
121
150
|
|
|
122
151
|
test('unwrap helpers', () => {
|
|
123
152
|
const warn = TernaryResult.warn('value', 'careful');
|
|
153
|
+
|
|
124
154
|
const err = TernaryResult.err('broken');
|
|
125
155
|
|
|
126
156
|
expect(TernaryResult.unwrapOk(TernaryResult.ok(3))).toBe(3);
|
|
157
|
+
|
|
127
158
|
expect(TernaryResult.unwrapOk(warn)).toBe('value');
|
|
159
|
+
|
|
128
160
|
expect(TernaryResult.unwrapWarn(warn)).toBe('careful');
|
|
161
|
+
|
|
129
162
|
expect(TernaryResult.unwrapErr(err)).toBe('broken');
|
|
163
|
+
|
|
130
164
|
expect(TernaryResult.unwrapOkOr(err, 0)).toBe(0);
|
|
165
|
+
|
|
131
166
|
expect(TernaryResult.unwrapWarnOr(err, 'default')).toBe('default');
|
|
167
|
+
|
|
132
168
|
expect(TernaryResult.unwrapErrOr(warn, 'default')).toBe('default');
|
|
133
169
|
});
|
|
134
170
|
|
|
@@ -136,9 +172,11 @@ describe('TernaryResult test', () => {
|
|
|
136
172
|
expect(() =>
|
|
137
173
|
TernaryResult.unwrapThrow(TernaryResult.warn('notice', 'warned')),
|
|
138
174
|
).toThrow(/Warn/u);
|
|
175
|
+
|
|
139
176
|
expect(() =>
|
|
140
177
|
TernaryResult.unwrapWarnThrow(TernaryResult.err('no warn')),
|
|
141
178
|
).toThrow(/Err/u);
|
|
179
|
+
|
|
142
180
|
expect(() =>
|
|
143
181
|
TernaryResult.unwrapErrThrow(TernaryResult.ok('no err')),
|
|
144
182
|
).toThrow(/Ok/u);
|
|
@@ -146,6 +184,7 @@ describe('TernaryResult test', () => {
|
|
|
146
184
|
|
|
147
185
|
test('expectToBe unwraps Ok values', () => {
|
|
148
186
|
expect(TernaryResult.expectToBe(TernaryResult.ok('v'), 'msg')).toBe('v');
|
|
187
|
+
|
|
149
188
|
expect(() =>
|
|
150
189
|
TernaryResult.expectToBe(TernaryResult.err('x'), 'missing'),
|
|
151
190
|
).toThrow(/missing/u);
|
|
@@ -153,22 +192,28 @@ describe('TernaryResult test', () => {
|
|
|
153
192
|
|
|
154
193
|
test('zip prefers Err over Warn or Ok.', () => {
|
|
155
194
|
const ok = TernaryResult.ok('x');
|
|
195
|
+
|
|
156
196
|
const warn = TernaryResult.warn('warn', 'warned');
|
|
197
|
+
|
|
157
198
|
const err = TernaryResult.err('err');
|
|
158
199
|
|
|
159
200
|
assert.deepStrictEqual(
|
|
160
201
|
TernaryResult.zip(ok, TernaryResult.ok(1)),
|
|
161
202
|
TernaryResult.ok(['x', 1] as const),
|
|
162
203
|
);
|
|
204
|
+
|
|
163
205
|
assert.deepStrictEqual(
|
|
164
206
|
TernaryResult.zip(ok, warn),
|
|
165
207
|
TernaryResult.warn(['x', 'warn'] as const, 'warned'),
|
|
166
208
|
);
|
|
209
|
+
|
|
167
210
|
assert.deepStrictEqual(
|
|
168
211
|
TernaryResult.zip(warn, ok),
|
|
169
212
|
TernaryResult.warn(['warn', 'x'] as const, 'warned'),
|
|
170
213
|
);
|
|
214
|
+
|
|
171
215
|
assert.deepStrictEqual(TernaryResult.zip(ok, err), err);
|
|
216
|
+
|
|
172
217
|
assert.deepStrictEqual(TernaryResult.zip(err, warn), err);
|
|
173
218
|
});
|
|
174
219
|
|
|
@@ -177,6 +222,7 @@ describe('TernaryResult test', () => {
|
|
|
177
222
|
TernaryResult.toOptional(TernaryResult.ok(1)),
|
|
178
223
|
Optional.some(1),
|
|
179
224
|
);
|
|
225
|
+
|
|
180
226
|
assert.deepStrictEqual(
|
|
181
227
|
TernaryResult.toOptional(TernaryResult.warn(1, 'warn')),
|
|
182
228
|
Optional.some(1),
|
|
@@ -211,4 +257,49 @@ describe('TernaryResult test', () => {
|
|
|
211
257
|
|
|
212
258
|
expect(TernaryResult.isErr(errorResult)).toBe(true);
|
|
213
259
|
});
|
|
260
|
+
|
|
261
|
+
test('unwrapOkOr curried version', () => {
|
|
262
|
+
const unwrap = TernaryResult.unwrapOkOr(999);
|
|
263
|
+
|
|
264
|
+
expect(unwrap(TernaryResult.ok(42))).toBe(42);
|
|
265
|
+
|
|
266
|
+
expect(unwrap(TernaryResult.warn(10, 'notice'))).toBe(10);
|
|
267
|
+
|
|
268
|
+
expect(unwrap(TernaryResult.err('error'))).toBe(999);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('unwrapWarnOr curried version', () => {
|
|
272
|
+
const unwrap = TernaryResult.unwrapWarnOr('default');
|
|
273
|
+
|
|
274
|
+
expect(unwrap(TernaryResult.warn(1, 'alert'))).toBe('alert');
|
|
275
|
+
|
|
276
|
+
expect(unwrap(TernaryResult.ok(5))).toBe('default');
|
|
277
|
+
|
|
278
|
+
expect(unwrap(TernaryResult.err('fail'))).toBe('default');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('unwrapErrOr curried version', () => {
|
|
282
|
+
const unwrap = TernaryResult.unwrapErrOr('fallback');
|
|
283
|
+
|
|
284
|
+
expect(unwrap(TernaryResult.err('bad'))).toBe('bad');
|
|
285
|
+
|
|
286
|
+
expect(unwrap(TernaryResult.ok(3))).toBe('fallback');
|
|
287
|
+
|
|
288
|
+
expect(unwrap(TernaryResult.warn(1, 'note'))).toBe('fallback');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test('orElse curried version', () => {
|
|
292
|
+
const fallback = TernaryResult.ok('backup');
|
|
293
|
+
|
|
294
|
+
const useBackup = TernaryResult.orElse(fallback);
|
|
295
|
+
|
|
296
|
+
assert.deepStrictEqual(useBackup(TernaryResult.ok(1)), TernaryResult.ok(1));
|
|
297
|
+
|
|
298
|
+
assert.deepStrictEqual(
|
|
299
|
+
useBackup(TernaryResult.warn(2, 'w')),
|
|
300
|
+
TernaryResult.warn(2, 'w'),
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
assert.deepStrictEqual(useBackup(TernaryResult.err('e')), fallback);
|
|
304
|
+
});
|
|
214
305
|
});
|