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,15 +9,22 @@ describe('Stack test', () => {
|
|
|
9
9
|
const stack = createStack<number>();
|
|
10
10
|
|
|
11
11
|
expectType<typeof stack, Stack<number>>('=');
|
|
12
|
+
|
|
12
13
|
expectType<typeof stack.isEmpty, boolean>('=');
|
|
14
|
+
|
|
13
15
|
expectType<typeof stack.size, SizeType.Arr>('=');
|
|
16
|
+
|
|
14
17
|
expectType<typeof stack.pop, () => Optional<number>>('=');
|
|
18
|
+
|
|
15
19
|
expectType<typeof stack.push, (value: number) => void>('=');
|
|
16
20
|
|
|
17
21
|
// Verify the type checking works at runtime too
|
|
18
22
|
expectTypeOf(stack.isEmpty).toBeBoolean();
|
|
23
|
+
|
|
19
24
|
expectTypeOf(stack.size).toBeNumber();
|
|
25
|
+
|
|
20
26
|
expectTypeOf(stack.pop).toBeFunction();
|
|
27
|
+
|
|
21
28
|
expectTypeOf(stack.push).toBeFunction();
|
|
22
29
|
});
|
|
23
30
|
|
|
@@ -25,6 +32,7 @@ describe('Stack test', () => {
|
|
|
25
32
|
const stack = createStack<string>();
|
|
26
33
|
|
|
27
34
|
expect(stack.isEmpty).toBe(true);
|
|
35
|
+
|
|
28
36
|
expect(stack.size).toBe(0);
|
|
29
37
|
});
|
|
30
38
|
|
|
@@ -32,12 +40,16 @@ describe('Stack test', () => {
|
|
|
32
40
|
const stack = createStack<number>([1, 2, 3]);
|
|
33
41
|
|
|
34
42
|
expect(stack.isEmpty).toBe(false);
|
|
43
|
+
|
|
35
44
|
expect(stack.size).toBe(3);
|
|
36
45
|
|
|
37
46
|
// Last element should be on top (LIFO)
|
|
38
47
|
expect(Optional.unwrap(stack.pop())).toBe(3);
|
|
48
|
+
|
|
39
49
|
expect(Optional.unwrap(stack.pop())).toBe(2);
|
|
50
|
+
|
|
40
51
|
expect(Optional.unwrap(stack.pop())).toBe(1);
|
|
52
|
+
|
|
41
53
|
expect(stack.isEmpty).toBe(true);
|
|
42
54
|
});
|
|
43
55
|
|
|
@@ -45,20 +57,26 @@ describe('Stack test', () => {
|
|
|
45
57
|
const stack = createStack<string>();
|
|
46
58
|
|
|
47
59
|
stack.push('first');
|
|
60
|
+
|
|
48
61
|
// eslint-disable-next-line unicorn/prefer-single-call
|
|
49
62
|
stack.push('second');
|
|
63
|
+
|
|
50
64
|
// eslint-disable-next-line unicorn/prefer-single-call
|
|
51
65
|
stack.push('third');
|
|
52
66
|
|
|
53
67
|
expect(stack.size).toBe(3);
|
|
68
|
+
|
|
54
69
|
expect(stack.isEmpty).toBe(false);
|
|
55
70
|
|
|
56
71
|
// LIFO: Last In, First Out
|
|
57
72
|
expect(Optional.unwrap(stack.pop())).toBe('third');
|
|
73
|
+
|
|
58
74
|
expect(Optional.unwrap(stack.pop())).toBe('second');
|
|
75
|
+
|
|
59
76
|
expect(Optional.unwrap(stack.pop())).toBe('first');
|
|
60
77
|
|
|
61
78
|
expect(stack.isEmpty).toBe(true);
|
|
79
|
+
|
|
62
80
|
expect(stack.size).toBe(0);
|
|
63
81
|
});
|
|
64
82
|
|
|
@@ -68,7 +86,9 @@ describe('Stack test', () => {
|
|
|
68
86
|
const result = stack.pop();
|
|
69
87
|
|
|
70
88
|
expect(Optional.isNone(result)).toBe(true);
|
|
89
|
+
|
|
71
90
|
expect(stack.isEmpty).toBe(true);
|
|
91
|
+
|
|
72
92
|
expect(stack.size).toBe(0);
|
|
73
93
|
});
|
|
74
94
|
|
|
@@ -100,6 +120,7 @@ describe('Stack test', () => {
|
|
|
100
120
|
Optional.unwrap(stack.pop());
|
|
101
121
|
|
|
102
122
|
expect(stack.size).toBe(0);
|
|
123
|
+
|
|
103
124
|
expect(stack.isEmpty).toBe(true);
|
|
104
125
|
});
|
|
105
126
|
|
|
@@ -107,17 +128,21 @@ describe('Stack test', () => {
|
|
|
107
128
|
const stack = createStack<string>();
|
|
108
129
|
|
|
109
130
|
stack.push('a');
|
|
131
|
+
|
|
110
132
|
// eslint-disable-next-line unicorn/prefer-single-call
|
|
111
133
|
stack.push('b');
|
|
112
134
|
|
|
113
135
|
expect(Optional.unwrap(stack.pop())).toBe('b');
|
|
114
136
|
|
|
115
137
|
stack.push('c');
|
|
138
|
+
|
|
116
139
|
// eslint-disable-next-line unicorn/prefer-single-call
|
|
117
140
|
stack.push('d');
|
|
118
141
|
|
|
119
142
|
expect(Optional.unwrap(stack.pop())).toBe('d');
|
|
143
|
+
|
|
120
144
|
expect(Optional.unwrap(stack.pop())).toBe('c');
|
|
145
|
+
|
|
121
146
|
expect(Optional.unwrap(stack.pop())).toBe('a');
|
|
122
147
|
|
|
123
148
|
expect(stack.isEmpty).toBe(true);
|
|
@@ -125,16 +150,20 @@ describe('Stack test', () => {
|
|
|
125
150
|
|
|
126
151
|
test('should work with object types', () => {
|
|
127
152
|
type Item = Readonly<{ id: number; name: string }>;
|
|
153
|
+
|
|
128
154
|
const stack = createStack<Item>();
|
|
129
155
|
|
|
130
156
|
const item1: Item = { id: 1, name: 'first' };
|
|
157
|
+
|
|
131
158
|
const item2: Item = { id: 2, name: 'second' };
|
|
132
159
|
|
|
133
160
|
stack.push(item1);
|
|
161
|
+
|
|
134
162
|
// eslint-disable-next-line unicorn/prefer-single-call
|
|
135
163
|
stack.push(item2);
|
|
136
164
|
|
|
137
165
|
assert.deepStrictEqual(Optional.unwrap(stack.pop()), item2);
|
|
166
|
+
|
|
138
167
|
assert.deepStrictEqual(Optional.unwrap(stack.pop()), item1);
|
|
139
168
|
|
|
140
169
|
expect(stack.isEmpty).toBe(true);
|
|
@@ -142,6 +171,7 @@ describe('Stack test', () => {
|
|
|
142
171
|
|
|
143
172
|
test('should handle large number of operations efficiently', () => {
|
|
144
173
|
const stack = createStack<number>();
|
|
174
|
+
|
|
145
175
|
const n = asPositiveSafeInt(10_000);
|
|
146
176
|
|
|
147
177
|
// Push many elements
|
|
@@ -150,6 +180,7 @@ describe('Stack test', () => {
|
|
|
150
180
|
}
|
|
151
181
|
|
|
152
182
|
expect(stack.size).toBe(n);
|
|
183
|
+
|
|
153
184
|
expect(stack.isEmpty).toBe(false);
|
|
154
185
|
|
|
155
186
|
// Pop all elements and verify LIFO order
|
|
@@ -157,21 +188,25 @@ describe('Stack test', () => {
|
|
|
157
188
|
const result = stack.pop();
|
|
158
189
|
|
|
159
190
|
expect(Optional.isSome(result)).toBe(true);
|
|
191
|
+
|
|
160
192
|
expect(Optional.unwrap(result)).toBe(i);
|
|
161
193
|
}
|
|
162
194
|
|
|
163
195
|
expect(stack.isEmpty).toBe(true);
|
|
196
|
+
|
|
164
197
|
expect(stack.size).toBe(0);
|
|
165
198
|
});
|
|
166
199
|
|
|
167
200
|
test('should not mutate initial values array', () => {
|
|
168
201
|
const initialValues = [1, 2, 3];
|
|
202
|
+
|
|
169
203
|
const originalLength = initialValues.length;
|
|
170
204
|
|
|
171
205
|
const stack = createStack(initialValues);
|
|
172
206
|
|
|
173
207
|
// Modify stack
|
|
174
208
|
stack.push(4);
|
|
209
|
+
|
|
175
210
|
Optional.unwrap(stack.pop());
|
|
176
211
|
|
|
177
212
|
// Original array should be unchanged
|
|
@@ -184,17 +219,24 @@ describe('Stack test', () => {
|
|
|
184
219
|
const stack = createStack<string | null | undefined>();
|
|
185
220
|
|
|
186
221
|
stack.push('value');
|
|
222
|
+
|
|
187
223
|
// eslint-disable-next-line unicorn/prefer-single-call
|
|
188
224
|
stack.push(null);
|
|
225
|
+
|
|
189
226
|
// eslint-disable-next-line unicorn/prefer-single-call
|
|
190
227
|
stack.push(undefined);
|
|
228
|
+
|
|
191
229
|
// eslint-disable-next-line unicorn/prefer-single-call
|
|
192
230
|
stack.push('another');
|
|
193
231
|
|
|
194
232
|
expect(Optional.unwrap(stack.pop())).toBe('another');
|
|
233
|
+
|
|
195
234
|
expect(Optional.unwrap(stack.pop())).toBeUndefined();
|
|
235
|
+
|
|
196
236
|
expect(Optional.unwrap(stack.pop())).toBeNull();
|
|
237
|
+
|
|
197
238
|
expect(Optional.unwrap(stack.pop())).toBe('value');
|
|
239
|
+
|
|
198
240
|
expect(stack.isEmpty).toBe(true);
|
|
199
241
|
});
|
|
200
242
|
|
|
@@ -215,6 +257,7 @@ describe('Stack test', () => {
|
|
|
215
257
|
}
|
|
216
258
|
|
|
217
259
|
const endTime = performance.now();
|
|
260
|
+
|
|
218
261
|
const duration = endTime - startTime;
|
|
219
262
|
|
|
220
263
|
// Should complete in reasonable time (much less than 100ms for 512 operations)
|
|
@@ -226,6 +269,7 @@ describe('Stack test', () => {
|
|
|
226
269
|
|
|
227
270
|
for (const i of range(100)) {
|
|
228
271
|
stack.push(i);
|
|
272
|
+
|
|
229
273
|
if (i % 2 === 1) {
|
|
230
274
|
// Pop every other time
|
|
231
275
|
const result = stack.pop();
|
package/src/functional/match.mts
CHANGED
|
@@ -70,10 +70,13 @@ export function match<
|
|
|
70
70
|
switch (args.length) {
|
|
71
71
|
case 2: {
|
|
72
72
|
const [target, cases] = args;
|
|
73
|
+
|
|
73
74
|
return cases[target];
|
|
74
75
|
}
|
|
76
|
+
|
|
75
77
|
case 3: {
|
|
76
78
|
const [target, cases, defaultValue] = args;
|
|
79
|
+
|
|
77
80
|
return keyIsIn(target, cases) ? cases[target] : defaultValue;
|
|
78
81
|
}
|
|
79
82
|
}
|
|
@@ -102,8 +105,11 @@ type AllCasesCovered<Case extends PropertyKey, R> =
|
|
|
102
105
|
TypeEq<Case, keyof R> extends true ? true : false;
|
|
103
106
|
|
|
104
107
|
expectType<AllCasesCovered<'a' | 'b', { a: 1; b: 2 }>, true>('=');
|
|
108
|
+
|
|
105
109
|
expectType<AllCasesCovered<'a' | 'b' | 'c', { a: 1; b: 2 }>, false>('=');
|
|
110
|
+
|
|
106
111
|
expectType<AllCasesCovered<'a' | 'b', { a: 1; b: 2; c: 3 }>, false>('=');
|
|
112
|
+
|
|
107
113
|
expectType<AllCasesCovered<string, Record<string, string>>, true>('=');
|
|
108
114
|
|
|
109
115
|
/**
|
|
@@ -121,15 +127,19 @@ type IsLiteralUnionFullyCovered<
|
|
|
121
127
|
: false;
|
|
122
128
|
|
|
123
129
|
expectType<IsLiteralUnionFullyCovered<'a' | 'b', { a: 1; b: 2 }>, true>('=');
|
|
130
|
+
|
|
124
131
|
expectType<IsLiteralUnionFullyCovered<'a' | 'b' | 'c', { a: 1; b: 2 }>, false>(
|
|
125
132
|
'=',
|
|
126
133
|
);
|
|
134
|
+
|
|
127
135
|
expectType<IsLiteralUnionFullyCovered<'a' | 'b', { a: 1; b: 2; c: 3 }>, false>(
|
|
128
136
|
'=',
|
|
129
137
|
);
|
|
138
|
+
|
|
130
139
|
expectType<IsLiteralUnionFullyCovered<string, Record<string, string>>, false>(
|
|
131
140
|
'=',
|
|
132
141
|
);
|
|
142
|
+
|
|
133
143
|
expectType<
|
|
134
144
|
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
135
145
|
IsLiteralUnionFullyCovered<'a' | 'b' | string, { a: 1; b: 2 }>,
|
|
@@ -152,9 +162,15 @@ type IsLiteralType<T extends PropertyKey> = string extends T
|
|
|
152
162
|
: true;
|
|
153
163
|
|
|
154
164
|
expectType<IsLiteralType<'a' | 'b'>, true>('=');
|
|
165
|
+
|
|
155
166
|
expectType<IsLiteralType<'a'>, true>('=');
|
|
167
|
+
|
|
156
168
|
expectType<IsLiteralType<string>, false>('=');
|
|
169
|
+
|
|
157
170
|
expectType<IsLiteralType<number>, false>('=');
|
|
171
|
+
|
|
158
172
|
expectType<IsLiteralType<1>, true>('=');
|
|
173
|
+
|
|
159
174
|
expectType<IsLiteralType<number | 'aa'>, false>('=');
|
|
175
|
+
|
|
160
176
|
expectType<IsLiteralType<'aa' | 32>, true>('=');
|
|
@@ -3,6 +3,7 @@ import { match } from './match.mjs';
|
|
|
3
3
|
|
|
4
4
|
describe(match, () => {
|
|
5
5
|
type Direction = 'E' | 'N' | 'S' | 'W';
|
|
6
|
+
|
|
6
7
|
const direction: Direction = 'N' as Direction;
|
|
7
8
|
|
|
8
9
|
test('literal union', () => {
|
|
@@ -159,6 +160,7 @@ describe(match, () => {
|
|
|
159
160
|
|
|
160
161
|
test('with default case - string key missing', () => {
|
|
161
162
|
const unknownDirection = 'X' as string;
|
|
163
|
+
|
|
162
164
|
const res = match(
|
|
163
165
|
unknownDirection,
|
|
164
166
|
{
|
|
@@ -16,6 +16,7 @@ import { type Unwrap } from './types.mjs';
|
|
|
16
16
|
* const expectValue = Optional.expectToBe<string>('missing optional');
|
|
17
17
|
*
|
|
18
18
|
* assert.throws(() => expectValue(Optional.none), /missing optional/u);
|
|
19
|
+
*
|
|
19
20
|
* assert(expectValue(Optional.some('present')) === 'present');
|
|
20
21
|
* ```
|
|
21
22
|
*
|
|
@@ -41,12 +42,14 @@ export function expectToBe<O extends UnknownOptional>(
|
|
|
41
42
|
switch (args.length) {
|
|
42
43
|
case 2: {
|
|
43
44
|
const [optional, message] = args;
|
|
45
|
+
|
|
44
46
|
return expectToBeImpl(optional, message);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
case 1: {
|
|
48
50
|
// Curried version: first argument is message
|
|
49
51
|
const [message] = args;
|
|
52
|
+
|
|
50
53
|
return (optional: Optional<Unwrap<O>>): Unwrap<O> =>
|
|
51
54
|
expectToBeImpl(optional, message);
|
|
52
55
|
}
|
|
@@ -13,14 +13,17 @@ import { type Unwrap } from './types.mjs';
|
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
15
|
* const even = Optional.filter(Optional.some(4), (value) => value % 2 === 0);
|
|
16
|
+
*
|
|
16
17
|
* const odd = Optional.filter(Optional.some(3), (value) => value % 2 === 0);
|
|
17
18
|
*
|
|
18
19
|
* assert.deepStrictEqual(even, Optional.some(4));
|
|
20
|
+
*
|
|
19
21
|
* assert.deepStrictEqual(odd, Optional.none);
|
|
20
22
|
*
|
|
21
23
|
* const filterEven = Optional.filter((value: number) => value % 2 === 0);
|
|
22
24
|
*
|
|
23
25
|
* assert.deepStrictEqual(filterEven(Optional.some(6)), Optional.some(6));
|
|
26
|
+
*
|
|
24
27
|
* assert.deepStrictEqual(filterEven(Optional.some(5)), Optional.none);
|
|
25
28
|
* ```
|
|
26
29
|
*
|
|
@@ -47,12 +50,14 @@ export function filter<O extends UnknownOptional>(
|
|
|
47
50
|
switch (args.length) {
|
|
48
51
|
case 2: {
|
|
49
52
|
const [optional, predicate] = args;
|
|
53
|
+
|
|
50
54
|
return filterImpl(optional, predicate);
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
case 1: {
|
|
54
58
|
// Curried version: first argument is predicate function
|
|
55
59
|
const [predicate] = args;
|
|
60
|
+
|
|
56
61
|
return (optional: O) => filterImpl(optional, predicate);
|
|
57
62
|
}
|
|
58
63
|
}
|
|
@@ -64,6 +69,7 @@ const filterImpl = <O extends UnknownOptional>(
|
|
|
64
69
|
): Optional<Unwrap<O>> => {
|
|
65
70
|
if (isSome(optional)) {
|
|
66
71
|
const value = unwrap(optional);
|
|
72
|
+
|
|
67
73
|
return predicate(value) ? some(value) : none;
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -13,6 +13,7 @@ import { type Unwrap } from './types.mjs';
|
|
|
13
13
|
* ```ts
|
|
14
14
|
* const parseNumber = (input: string): Optional<number> => {
|
|
15
15
|
* const num = Number.parseInt(input, 10);
|
|
16
|
+
*
|
|
16
17
|
* return Number.isNaN(num) ? Optional.none : Optional.some(num);
|
|
17
18
|
* };
|
|
18
19
|
*
|
|
@@ -23,6 +24,7 @@ import { type Unwrap } from './types.mjs';
|
|
|
23
24
|
* const flatMapParse = Optional.flatMap(parseNumber);
|
|
24
25
|
*
|
|
25
26
|
* assert.deepStrictEqual(flatMapParse(Optional.some('5')), Optional.some(5));
|
|
27
|
+
*
|
|
26
28
|
* assert.deepStrictEqual(flatMapParse(Optional.some('invalid')), Optional.none);
|
|
27
29
|
* ```
|
|
28
30
|
*
|
|
@@ -50,12 +52,14 @@ export function flatMap<O extends UnknownOptional, S2>(
|
|
|
50
52
|
switch (args.length) {
|
|
51
53
|
case 2: {
|
|
52
54
|
const [optional, flatMapFn] = args;
|
|
55
|
+
|
|
53
56
|
return flatMapImpl(optional, flatMapFn);
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
case 1: {
|
|
57
60
|
// Curried version
|
|
58
61
|
const [flatMapFn] = args;
|
|
62
|
+
|
|
59
63
|
return (optional: O) => flatMapImpl(optional, flatMapFn);
|
|
60
64
|
}
|
|
61
65
|
}
|
|
@@ -12,9 +12,11 @@ import { some } from './optional-some.mjs';
|
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
14
|
* const present = Optional.fromNullable('hello');
|
|
15
|
+
*
|
|
15
16
|
* const absent = Optional.fromNullable<string | null>(null);
|
|
16
17
|
*
|
|
17
18
|
* assert.deepStrictEqual(present, Optional.some('hello'));
|
|
19
|
+
*
|
|
18
20
|
* assert.deepStrictEqual(absent, Optional.none);
|
|
19
21
|
* ```
|
|
20
22
|
*
|
|
@@ -8,9 +8,11 @@ import { NoneTypeTagName, SomeTypeTagName } from './tag.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const maybeOptional = Optional.some('value');
|
|
11
|
+
*
|
|
11
12
|
* const notOptional = { $$tag: 'ts-data-forge::Optional.some' };
|
|
12
13
|
*
|
|
13
14
|
* assert.ok(Optional.isOptional(maybeOptional));
|
|
15
|
+
*
|
|
14
16
|
* assert.notOk(Optional.isOptional(notOptional));
|
|
15
17
|
* ```
|
|
16
18
|
*
|
|
@@ -14,6 +14,7 @@ import { type Unwrap } from './types.mjs';
|
|
|
14
14
|
*
|
|
15
15
|
* ```ts
|
|
16
16
|
* const numberOptional = Optional.some(21);
|
|
17
|
+
*
|
|
17
18
|
* const mapped = Optional.map(numberOptional, (value) => value * 2);
|
|
18
19
|
*
|
|
19
20
|
* assert.deepStrictEqual(mapped, Optional.some(42));
|
|
@@ -21,6 +22,7 @@ import { type Unwrap } from './types.mjs';
|
|
|
21
22
|
* const mapToLength = Optional.map((text: string) => text.length);
|
|
22
23
|
*
|
|
23
24
|
* assert.deepStrictEqual(mapToLength(Optional.some('abc')), Optional.some(3));
|
|
25
|
+
*
|
|
24
26
|
* assert.deepStrictEqual(mapToLength(Optional.none), Optional.none);
|
|
25
27
|
* ```
|
|
26
28
|
*
|
|
@@ -49,11 +51,14 @@ export function map<O extends UnknownOptional, S2>(
|
|
|
49
51
|
switch (args.length) {
|
|
50
52
|
case 2: {
|
|
51
53
|
const [optional, mapFn] = args;
|
|
54
|
+
|
|
52
55
|
return mapImpl(optional, mapFn);
|
|
53
56
|
}
|
|
57
|
+
|
|
54
58
|
case 1: {
|
|
55
59
|
// Curried version: first argument is mapping function
|
|
56
60
|
const [mapFn] = args;
|
|
61
|
+
|
|
57
62
|
return (optional: O) => mapImpl(optional, mapFn);
|
|
58
63
|
}
|
|
59
64
|
}
|
|
@@ -8,9 +8,11 @@ import { NoneTypeTagName } from './tag.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* const someValue = Optional.some({ id: 1 });
|
|
11
|
+
*
|
|
11
12
|
* const noneValue = Optional.none;
|
|
12
13
|
*
|
|
13
14
|
* assert.ok(Optional.isSome(someValue));
|
|
15
|
+
*
|
|
14
16
|
* assert.ok(Optional.isNone(noneValue));
|
|
15
17
|
* ```
|
|
16
18
|
*/
|
|
@@ -12,15 +12,19 @@ import { type Unwrap } from './types.mjs';
|
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
14
|
* const preferred = Optional.some('primary');
|
|
15
|
+
*
|
|
15
16
|
* const fallback = Optional.some('secondary');
|
|
17
|
+
*
|
|
16
18
|
* const noneValue = Optional.none as Optional<string>;
|
|
17
19
|
*
|
|
18
20
|
* assert.deepStrictEqual(Optional.orElse(preferred, fallback), preferred);
|
|
21
|
+
*
|
|
19
22
|
* assert.deepStrictEqual(Optional.orElse(noneValue, fallback), fallback);
|
|
20
23
|
*
|
|
21
24
|
* const orElseFallback = Optional.orElse(Optional.some('default'));
|
|
22
25
|
*
|
|
23
26
|
* assert.deepStrictEqual(orElseFallback(Optional.none), Optional.some('default'));
|
|
27
|
+
*
|
|
24
28
|
* assert.deepStrictEqual(
|
|
25
29
|
* orElseFallback(Optional.some('value')),
|
|
26
30
|
* Optional.some('value'),
|
|
@@ -52,12 +56,14 @@ export function orElse<
|
|
|
52
56
|
switch (args.length) {
|
|
53
57
|
case 2: {
|
|
54
58
|
const [optional, alternative] = args;
|
|
59
|
+
|
|
55
60
|
return orElseImpl(optional, alternative);
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
case 1: {
|
|
59
64
|
// Curried version
|
|
60
65
|
const [alternative] = args;
|
|
66
|
+
|
|
61
67
|
return (optional: Optional<Unwrap<O>>) =>
|
|
62
68
|
orElseImpl(optional, alternative);
|
|
63
69
|
}
|
|
@@ -7,9 +7,11 @@ import { SomeTypeTagName } from './tag.mjs';
|
|
|
7
7
|
*
|
|
8
8
|
* ```ts
|
|
9
9
|
* const someValue = Optional.some({ id: 1 });
|
|
10
|
+
*
|
|
10
11
|
* const noneValue = Optional.none;
|
|
11
12
|
*
|
|
12
13
|
* assert.ok(Optional.isSome(someValue));
|
|
14
|
+
*
|
|
13
15
|
* assert.ok(Optional.isNone(noneValue));
|
|
14
16
|
* ```
|
|
15
17
|
*
|
|
@@ -17,7 +19,7 @@ import { SomeTypeTagName } from './tag.mjs';
|
|
|
17
19
|
* @param value The value to wrap in an {@link Some}.
|
|
18
20
|
* @returns An {@link Some}<S> containing the value.
|
|
19
21
|
*/
|
|
20
|
-
export const some = <S,>(value: S): Some<S> => ({
|
|
22
|
+
export const some = <const S,>(value: S): Some<S> => ({
|
|
21
23
|
$$tag: SomeTypeTagName,
|
|
22
24
|
value,
|
|
23
25
|
});
|
|
@@ -16,9 +16,11 @@ import { type Unwrap } from './types.mjs';
|
|
|
16
16
|
*
|
|
17
17
|
* ```ts
|
|
18
18
|
* const someNumber = Optional.some(42);
|
|
19
|
+
*
|
|
19
20
|
* const noneNumber = Optional.none as Optional<number>;
|
|
20
21
|
*
|
|
21
22
|
* assert(Optional.toNullable(someNumber) === 42);
|
|
23
|
+
*
|
|
22
24
|
* assert(Optional.toNullable(noneNumber) === undefined);
|
|
23
25
|
* ```
|
|
24
26
|
*
|
|
@@ -13,14 +13,17 @@ import { type Unwrap } from './types.mjs';
|
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
15
|
* const withValue = Optional.some(5);
|
|
16
|
+
*
|
|
16
17
|
* const withoutValue = Optional.none as Optional<number>;
|
|
17
18
|
*
|
|
18
19
|
* assert(Optional.unwrapOr(withValue, 0) === 5);
|
|
20
|
+
*
|
|
19
21
|
* assert(Optional.unwrapOr(withoutValue, 0) === 0);
|
|
20
22
|
*
|
|
21
23
|
* const unwrapWithDefault = Optional.unwrapOr(10);
|
|
22
24
|
*
|
|
23
25
|
* assert(unwrapWithDefault(Optional.some(3)) === 3);
|
|
26
|
+
*
|
|
24
27
|
* assert(unwrapWithDefault(Optional.none) === 10);
|
|
25
28
|
* ```
|
|
26
29
|
*
|
|
@@ -46,12 +49,14 @@ export function unwrapOr<O extends UnknownOptional, D>(
|
|
|
46
49
|
switch (args.length) {
|
|
47
50
|
case 2: {
|
|
48
51
|
const [optional, defaultValue] = args;
|
|
52
|
+
|
|
49
53
|
return unwrapOrImpl(optional, defaultValue);
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
case 1: {
|
|
53
57
|
// Curried version: first argument is default value
|
|
54
58
|
const [defaultValue] = args;
|
|
59
|
+
|
|
55
60
|
return (optional: Optional<Unwrap<O>>) =>
|
|
56
61
|
unwrapOrImpl(optional, defaultValue);
|
|
57
62
|
}
|
|
@@ -15,6 +15,7 @@ import { type Unwrap } from './types.mjs';
|
|
|
15
15
|
* const present = Optional.some('available');
|
|
16
16
|
*
|
|
17
17
|
* assert(Optional.unwrapThrow(present) === 'available');
|
|
18
|
+
*
|
|
18
19
|
* assert.throws(
|
|
19
20
|
* () => Optional.unwrapThrow(Optional.none),
|
|
20
21
|
* /has failed because it is `None`/u,
|
|
@@ -15,9 +15,11 @@ import { type Unwrap } from './types.mjs';
|
|
|
15
15
|
*
|
|
16
16
|
* ```ts
|
|
17
17
|
* const someString = Optional.some('text');
|
|
18
|
+
*
|
|
18
19
|
* const noneString = Optional.none as Optional<string>;
|
|
19
20
|
*
|
|
20
21
|
* assert(Optional.unwrap(someString) === 'text');
|
|
22
|
+
*
|
|
21
23
|
* assert(Optional.unwrap(noneString) === undefined);
|
|
22
24
|
* ```
|
|
23
25
|
*
|
|
@@ -12,8 +12,10 @@ import { some } from './optional-some.mjs';
|
|
|
12
12
|
* const zipped = Optional.zip(Optional.some('left'), Optional.some(1));
|
|
13
13
|
*
|
|
14
14
|
* assert.ok(Optional.isSome(zipped));
|
|
15
|
+
*
|
|
15
16
|
* if (Optional.isSome(zipped)) {
|
|
16
17
|
* const expected: readonly [string, number] = ['left', 1];
|
|
18
|
+
*
|
|
17
19
|
* assert.deepStrictEqual(zipped.value, expected);
|
|
18
20
|
* }
|
|
19
21
|
*
|