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,11 +9,15 @@ import { Optional, pipe } from '../../functional/index.mjs';
|
|
|
9
9
|
* const letters: readonly string[] = ['a', 'b', 'c'];
|
|
10
10
|
*
|
|
11
11
|
* const two = Arr.at(letters, 1);
|
|
12
|
+
*
|
|
12
13
|
* const last = Arr.at(-1)(letters);
|
|
14
|
+
*
|
|
13
15
|
* const missing = Arr.at(letters, 5);
|
|
14
16
|
*
|
|
15
17
|
* assert.deepStrictEqual(two, Optional.some('b'));
|
|
18
|
+
*
|
|
16
19
|
* assert.deepStrictEqual(last, Optional.some('c'));
|
|
20
|
+
*
|
|
17
21
|
* assert.deepStrictEqual(missing, Optional.none);
|
|
18
22
|
* ```
|
|
19
23
|
*/
|
|
@@ -36,6 +40,7 @@ export function at<E>(
|
|
|
36
40
|
switch (args.length) {
|
|
37
41
|
case 2: {
|
|
38
42
|
const [array, index] = args;
|
|
43
|
+
|
|
39
44
|
return pipe(index < 0 ? array.length + index : index).map(
|
|
40
45
|
(normalizedIndex) =>
|
|
41
46
|
normalizedIndex < 0 || normalizedIndex >= array.length
|
|
@@ -44,8 +49,10 @@ export function at<E>(
|
|
|
44
49
|
Optional.some(array[normalizedIndex]!),
|
|
45
50
|
).value;
|
|
46
51
|
}
|
|
52
|
+
|
|
47
53
|
case 1: {
|
|
48
54
|
const [index] = args;
|
|
55
|
+
|
|
49
56
|
return (array) => at(array, index);
|
|
50
57
|
}
|
|
51
58
|
}
|
|
@@ -58,12 +65,15 @@ export function at<E>(
|
|
|
58
65
|
*
|
|
59
66
|
* ```ts
|
|
60
67
|
* const users = [{ id: 1 }, { id: 2 }];
|
|
68
|
+
*
|
|
61
69
|
* const empty: { id: number }[] = [];
|
|
62
70
|
*
|
|
63
71
|
* const first = Arr.head(users);
|
|
72
|
+
*
|
|
64
73
|
* const none = Arr.head(empty);
|
|
65
74
|
*
|
|
66
75
|
* assert.deepStrictEqual(first, Optional.some({ id: 1 }));
|
|
76
|
+
*
|
|
67
77
|
* assert.deepStrictEqual(none, Optional.none);
|
|
68
78
|
* ```
|
|
69
79
|
*/
|
|
@@ -86,12 +96,15 @@ export const head = <const Ar extends readonly unknown[]>(
|
|
|
86
96
|
*
|
|
87
97
|
* ```ts
|
|
88
98
|
* const queue = ['first', 'second'];
|
|
99
|
+
*
|
|
89
100
|
* const emptyQueue: string[] = [];
|
|
90
101
|
*
|
|
91
102
|
* const lastValue = Arr.last(queue);
|
|
103
|
+
*
|
|
92
104
|
* const none = Arr.last(emptyQueue);
|
|
93
105
|
*
|
|
94
106
|
* assert.deepStrictEqual(lastValue, Optional.some('second'));
|
|
107
|
+
*
|
|
95
108
|
* assert.deepStrictEqual(none, Optional.none);
|
|
96
109
|
* ```
|
|
97
110
|
*/
|
|
@@ -7,6 +7,7 @@ describe('Arr element access', () => {
|
|
|
7
7
|
describe(at, () => {
|
|
8
8
|
test('should handle very large positive indices', () => {
|
|
9
9
|
const array = [1, 2, 3];
|
|
10
|
+
|
|
10
11
|
const result = at(array, asUint32(1000));
|
|
11
12
|
|
|
12
13
|
expect(Optional.isNone(result)).toBe(true);
|
|
@@ -14,6 +15,7 @@ describe('Arr element access', () => {
|
|
|
14
15
|
|
|
15
16
|
test('should handle very large negative indices', () => {
|
|
16
17
|
const array = [1, 2, 3];
|
|
18
|
+
|
|
17
19
|
const result = at(array, asInt32(-1000));
|
|
18
20
|
|
|
19
21
|
expect(Optional.isNone(result)).toBe(true);
|
|
@@ -21,6 +23,7 @@ describe('Arr element access', () => {
|
|
|
21
23
|
|
|
22
24
|
test('should work with valid indices', () => {
|
|
23
25
|
const array = [10, 20, 30];
|
|
26
|
+
|
|
24
27
|
const result = at(array, 1);
|
|
25
28
|
|
|
26
29
|
expect(Optional.isSome(result)).toBe(true);
|
|
@@ -29,11 +32,24 @@ describe('Arr element access', () => {
|
|
|
29
32
|
expect(result.value).toBe(20);
|
|
30
33
|
}
|
|
31
34
|
});
|
|
35
|
+
|
|
36
|
+
test('should work with curried version', () => {
|
|
37
|
+
const atIndex2 = at(2);
|
|
38
|
+
|
|
39
|
+
const result = atIndex2([10, 20, 30, 40]);
|
|
40
|
+
|
|
41
|
+
expect(Optional.isSome(result)).toBe(true);
|
|
42
|
+
|
|
43
|
+
if (Optional.isSome(result)) {
|
|
44
|
+
expect(result.value).toBe(30);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
32
47
|
});
|
|
33
48
|
|
|
34
49
|
describe(head, () => {
|
|
35
50
|
test('case 1', () => {
|
|
36
51
|
const xs = [1, 2, 3] as const;
|
|
52
|
+
|
|
37
53
|
const h = head(xs);
|
|
38
54
|
|
|
39
55
|
expectType<typeof h, Some<1>>('=');
|
|
@@ -47,6 +63,7 @@ describe('Arr element access', () => {
|
|
|
47
63
|
|
|
48
64
|
test('case 2', () => {
|
|
49
65
|
const xs: MutableNonEmptyArray<number> = [1, 2, 3];
|
|
66
|
+
|
|
50
67
|
const h = head(xs);
|
|
51
68
|
|
|
52
69
|
expectType<typeof h, Some<number>>('=');
|
|
@@ -60,6 +77,7 @@ describe('Arr element access', () => {
|
|
|
60
77
|
|
|
61
78
|
test('case 3', () => {
|
|
62
79
|
const mut_xs: number[] = [1, 2, 3];
|
|
80
|
+
|
|
63
81
|
const h = head(mut_xs);
|
|
64
82
|
|
|
65
83
|
expectType<typeof h, Optional<number>>('=');
|
|
@@ -101,6 +119,7 @@ describe('Arr element access', () => {
|
|
|
101
119
|
describe(last, () => {
|
|
102
120
|
test('case 1', () => {
|
|
103
121
|
const xs = [1, 2, 3] as const;
|
|
122
|
+
|
|
104
123
|
const l = last(xs);
|
|
105
124
|
|
|
106
125
|
expectType<typeof l, Some<3>>('=');
|
|
@@ -114,6 +133,7 @@ describe('Arr element access', () => {
|
|
|
114
133
|
|
|
115
134
|
test('case 2', () => {
|
|
116
135
|
const xs: MutableNonEmptyArray<number> = [1, 2, 3];
|
|
136
|
+
|
|
117
137
|
const l = last(xs);
|
|
118
138
|
|
|
119
139
|
expectType<typeof l, Some<number>>('=');
|
|
@@ -127,6 +147,7 @@ describe('Arr element access', () => {
|
|
|
127
147
|
|
|
128
148
|
test('case 3', () => {
|
|
129
149
|
const mut_xs: number[] = [1, 2, 3];
|
|
150
|
+
|
|
130
151
|
const l = last(mut_xs);
|
|
131
152
|
|
|
132
153
|
expectType<typeof l, Optional<number>>('=');
|
|
@@ -5,6 +5,7 @@ import { entries, indices, values } from './array-utils-iterators.mjs';
|
|
|
5
5
|
describe(entries, () => {
|
|
6
6
|
test('should return array of index-value pairs', () => {
|
|
7
7
|
const fruits = ['apple', 'banana', 'cherry'];
|
|
8
|
+
|
|
8
9
|
const es = Array.from(entries(fruits));
|
|
9
10
|
|
|
10
11
|
assert.deepStrictEqual(es, [
|
|
@@ -16,7 +17,9 @@ describe(entries, () => {
|
|
|
16
17
|
|
|
17
18
|
test('should work with tuples', () => {
|
|
18
19
|
const tuple = [10, 20, 30] as const;
|
|
20
|
+
|
|
19
21
|
const es = Array.from(entries(tuple));
|
|
22
|
+
|
|
20
23
|
expectType<typeof es, (readonly [Uint32, 10 | 20 | 30])[]>('=');
|
|
21
24
|
|
|
22
25
|
assert.deepStrictEqual(es, [
|
|
@@ -28,6 +31,7 @@ describe(entries, () => {
|
|
|
28
31
|
|
|
29
32
|
test('should work with empty array', () => {
|
|
30
33
|
const empty: string[] = [];
|
|
34
|
+
|
|
31
35
|
const es = Array.from(entries(empty));
|
|
32
36
|
|
|
33
37
|
assert.deepStrictEqual(es, []);
|
|
@@ -35,7 +39,9 @@ describe(entries, () => {
|
|
|
35
39
|
|
|
36
40
|
test('should preserve mixed types', () => {
|
|
37
41
|
const mixed = [1, 'hello', true] as const;
|
|
42
|
+
|
|
38
43
|
const es = Array.from(entries(mixed));
|
|
44
|
+
|
|
39
45
|
expectType<typeof es, (readonly [Uint32, 1 | 'hello' | true])[]>('=');
|
|
40
46
|
|
|
41
47
|
assert.deepStrictEqual(es, [
|
|
@@ -49,6 +55,7 @@ describe(entries, () => {
|
|
|
49
55
|
describe(values, () => {
|
|
50
56
|
test('should return copy of array values', () => {
|
|
51
57
|
const numbers = [1, 2, 3];
|
|
58
|
+
|
|
52
59
|
const vs = Array.from(values(numbers));
|
|
53
60
|
|
|
54
61
|
assert.deepStrictEqual(vs, [1, 2, 3]);
|
|
@@ -58,7 +65,9 @@ describe(values, () => {
|
|
|
58
65
|
|
|
59
66
|
test('should work with tuples', () => {
|
|
60
67
|
const tuple = ['a', 'b', 'c'] as const;
|
|
68
|
+
|
|
61
69
|
const vs = Array.from(values(tuple));
|
|
70
|
+
|
|
62
71
|
expectType<typeof vs, ('a' | 'b' | 'c')[]>('=');
|
|
63
72
|
|
|
64
73
|
assert.deepStrictEqual(vs, ['a', 'b', 'c']);
|
|
@@ -66,6 +75,7 @@ describe(values, () => {
|
|
|
66
75
|
|
|
67
76
|
test('should work with empty array', () => {
|
|
68
77
|
const empty: number[] = [];
|
|
78
|
+
|
|
69
79
|
const vs = Array.from(values(empty));
|
|
70
80
|
|
|
71
81
|
assert.deepStrictEqual(vs, []);
|
|
@@ -73,7 +83,9 @@ describe(values, () => {
|
|
|
73
83
|
|
|
74
84
|
test('should preserve mixed types', () => {
|
|
75
85
|
const mixed = [1, 'hello', null] as const;
|
|
86
|
+
|
|
76
87
|
const vs = Array.from(values(mixed));
|
|
88
|
+
|
|
77
89
|
expectType<typeof vs, (1 | 'hello' | null)[]>('=');
|
|
78
90
|
|
|
79
91
|
assert.deepStrictEqual(vs, [1, 'hello', null]);
|
|
@@ -83,6 +95,7 @@ describe(values, () => {
|
|
|
83
95
|
describe(indices, () => {
|
|
84
96
|
test('should return array of indices', () => {
|
|
85
97
|
const fruits = ['apple', 'banana', 'cherry'];
|
|
98
|
+
|
|
86
99
|
const ks = Array.from(indices(fruits));
|
|
87
100
|
|
|
88
101
|
assert.deepStrictEqual(ks, [asUint32(0), asUint32(1), asUint32(2)]);
|
|
@@ -90,7 +103,9 @@ describe(indices, () => {
|
|
|
90
103
|
|
|
91
104
|
test('should work with tuples', () => {
|
|
92
105
|
const tuple = ['a', 'b'] as const;
|
|
106
|
+
|
|
93
107
|
const ks = Array.from(indices(tuple));
|
|
108
|
+
|
|
94
109
|
expectType<typeof ks, Uint32[]>('=');
|
|
95
110
|
|
|
96
111
|
assert.deepStrictEqual(ks, [asUint32(0), asUint32(1)]);
|
|
@@ -98,6 +113,7 @@ describe(indices, () => {
|
|
|
98
113
|
|
|
99
114
|
test('should work with empty array', () => {
|
|
100
115
|
const empty: string[] = [];
|
|
116
|
+
|
|
101
117
|
const ks = Array.from(indices(empty));
|
|
102
118
|
|
|
103
119
|
assert.deepStrictEqual(ks, []);
|
|
@@ -105,6 +121,7 @@ describe(indices, () => {
|
|
|
105
121
|
|
|
106
122
|
test('should work with larger arrays', () => {
|
|
107
123
|
const large = Array.from({ length: 5 }, () => 'x');
|
|
124
|
+
|
|
108
125
|
const ks = Array.from(indices(large));
|
|
109
126
|
|
|
110
127
|
assert.deepStrictEqual(ks, [
|
|
@@ -45,11 +45,14 @@ export function set<E, const V = E>(
|
|
|
45
45
|
switch (args.length) {
|
|
46
46
|
case 3: {
|
|
47
47
|
const [array, index, newValue] = args;
|
|
48
|
+
|
|
48
49
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
49
50
|
return (array as (E | V)[]).with(index, newValue);
|
|
50
51
|
}
|
|
52
|
+
|
|
51
53
|
case 2: {
|
|
52
54
|
const [index, newValue] = args;
|
|
55
|
+
|
|
53
56
|
return (array) => set(array, index, newValue);
|
|
54
57
|
}
|
|
55
58
|
}
|
|
@@ -64,12 +67,14 @@ export function set<E, const V = E>(
|
|
|
64
67
|
* const temperatures: number[] = [20, 21, 22];
|
|
65
68
|
*
|
|
66
69
|
* const increased = Arr.toUpdated(temperatures, 1, (value) => value + 5);
|
|
70
|
+
*
|
|
67
71
|
* const incrementLast = Arr.toUpdated<number>(
|
|
68
72
|
* 2,
|
|
69
73
|
* (value) => value + 1,
|
|
70
74
|
* )(temperatures);
|
|
71
75
|
*
|
|
72
76
|
* assert.deepStrictEqual(increased, [20, 26, 22]);
|
|
77
|
+
*
|
|
73
78
|
* assert.deepStrictEqual(incrementLast, [20, 21, 23]);
|
|
74
79
|
* ```
|
|
75
80
|
*/
|
|
@@ -110,11 +115,14 @@ export function toUpdated<E, V = E>(
|
|
|
110
115
|
switch (args.length) {
|
|
111
116
|
case 3: {
|
|
112
117
|
const [array, index, updater] = args;
|
|
118
|
+
|
|
113
119
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, total-functions/no-unsafe-type-assertion
|
|
114
120
|
return (array as (E | V)[]).with(index, updater(array[index]!));
|
|
115
121
|
}
|
|
122
|
+
|
|
116
123
|
case 2: {
|
|
117
124
|
const [index, updater] = args;
|
|
125
|
+
|
|
118
126
|
return (array) => toUpdated(array, index, updater);
|
|
119
127
|
}
|
|
120
128
|
}
|
|
@@ -129,9 +137,11 @@ export function toUpdated<E, V = E>(
|
|
|
129
137
|
* const numbers = [1, 2, 4] as const;
|
|
130
138
|
*
|
|
131
139
|
* const withThree = Arr.toInserted(numbers, 2, 3);
|
|
140
|
+
*
|
|
132
141
|
* const appendFive = Arr.toInserted(3, 5)(numbers);
|
|
133
142
|
*
|
|
134
143
|
* assert.deepStrictEqual(withThree, [1, 2, 3, 4]);
|
|
144
|
+
*
|
|
135
145
|
* assert.deepStrictEqual(appendFive, [1, 2, 4, 5]);
|
|
136
146
|
* ```
|
|
137
147
|
*/
|
|
@@ -168,6 +178,7 @@ export function toInserted<E, const V = E>(
|
|
|
168
178
|
switch (args.length) {
|
|
169
179
|
case 3: {
|
|
170
180
|
const [array, index, newValue] = args;
|
|
181
|
+
|
|
171
182
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
172
183
|
return (array as readonly (E | V)[]).toSpliced(
|
|
173
184
|
index,
|
|
@@ -175,8 +186,10 @@ export function toInserted<E, const V = E>(
|
|
|
175
186
|
newValue,
|
|
176
187
|
) as unknown as NonEmptyArray<E | V>;
|
|
177
188
|
}
|
|
189
|
+
|
|
178
190
|
case 2: {
|
|
179
191
|
const [index, newValue] = args;
|
|
192
|
+
|
|
180
193
|
return (array) => toInserted(array, index, newValue);
|
|
181
194
|
}
|
|
182
195
|
}
|
|
@@ -193,9 +206,11 @@ type CastToNumber<T> = T extends number ? T : never;
|
|
|
193
206
|
* const letters = ['a', 'b', 'c', 'd'] as const;
|
|
194
207
|
*
|
|
195
208
|
* const withoutSecond = Arr.toRemoved(letters, 1);
|
|
209
|
+
*
|
|
196
210
|
* const withoutFirstCurried = Arr.toRemoved(0)(letters);
|
|
197
211
|
*
|
|
198
212
|
* assert.deepStrictEqual(withoutSecond, ['a', 'c', 'd']);
|
|
213
|
+
*
|
|
199
214
|
* assert.deepStrictEqual(withoutFirstCurried, ['b', 'c', 'd']);
|
|
200
215
|
* ```
|
|
201
216
|
*/
|
|
@@ -216,10 +231,13 @@ export function toRemoved<E>(
|
|
|
216
231
|
switch (args.length) {
|
|
217
232
|
case 2: {
|
|
218
233
|
const [array, index] = args;
|
|
234
|
+
|
|
219
235
|
return array.toSpliced(index, 1);
|
|
220
236
|
}
|
|
237
|
+
|
|
221
238
|
case 1: {
|
|
222
239
|
const [index] = args;
|
|
240
|
+
|
|
223
241
|
return (array) => toRemoved(array, index);
|
|
224
242
|
}
|
|
225
243
|
}
|
|
@@ -234,9 +252,11 @@ export function toRemoved<E>(
|
|
|
234
252
|
* const base = [1, 2] as const;
|
|
235
253
|
*
|
|
236
254
|
* const appended = Arr.toPushed(base, 3);
|
|
255
|
+
*
|
|
237
256
|
* const appendedCurried = Arr.toPushed(4)(base);
|
|
238
257
|
*
|
|
239
258
|
* assert.deepStrictEqual(appended, [1, 2, 3]);
|
|
259
|
+
*
|
|
240
260
|
* assert.deepStrictEqual(appendedCurried, [1, 2, 4]);
|
|
241
261
|
* ```
|
|
242
262
|
*/
|
|
@@ -255,14 +275,17 @@ export function toPushed<const Ar extends readonly unknown[], const V>(
|
|
|
255
275
|
switch (args.length) {
|
|
256
276
|
case 2: {
|
|
257
277
|
const [array, newValue] = args;
|
|
278
|
+
|
|
258
279
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
259
280
|
return array.toSpliced(array.length, 0, newValue) as unknown as readonly [
|
|
260
281
|
...Ar,
|
|
261
282
|
V,
|
|
262
283
|
];
|
|
263
284
|
}
|
|
285
|
+
|
|
264
286
|
case 1: {
|
|
265
287
|
const [newValue] = args;
|
|
288
|
+
|
|
266
289
|
return (array) => toPushed(array, newValue);
|
|
267
290
|
}
|
|
268
291
|
}
|
|
@@ -277,9 +300,11 @@ export function toPushed<const Ar extends readonly unknown[], const V>(
|
|
|
277
300
|
* const base = [2, 3] as const;
|
|
278
301
|
*
|
|
279
302
|
* const prefixed = Arr.toUnshifted(base, 1);
|
|
303
|
+
*
|
|
280
304
|
* const prefixedCurried = Arr.toUnshifted(0)(base);
|
|
281
305
|
*
|
|
282
306
|
* assert.deepStrictEqual(prefixed, [1, 2, 3]);
|
|
307
|
+
*
|
|
283
308
|
* assert.deepStrictEqual(prefixedCurried, [0, 2, 3]);
|
|
284
309
|
* ```
|
|
285
310
|
*/
|
|
@@ -298,11 +323,14 @@ export function toUnshifted<Ar extends readonly unknown[], const V>(
|
|
|
298
323
|
switch (args.length) {
|
|
299
324
|
case 2: {
|
|
300
325
|
const [array, newValue] = args;
|
|
326
|
+
|
|
301
327
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
302
328
|
return array.toSpliced(0, 0, newValue) as unknown as readonly [V, ...Ar];
|
|
303
329
|
}
|
|
330
|
+
|
|
304
331
|
case 1: {
|
|
305
332
|
const [newValue] = args;
|
|
333
|
+
|
|
306
334
|
return (array) => toUnshifted(array, newValue);
|
|
307
335
|
}
|
|
308
336
|
}
|
|
@@ -317,9 +345,11 @@ export function toUnshifted<Ar extends readonly unknown[], const V>(
|
|
|
317
345
|
* const base = [1, 2, 3];
|
|
318
346
|
*
|
|
319
347
|
* const filled = Arr.toFilled(base, 0);
|
|
348
|
+
*
|
|
320
349
|
* const filledCurried = Arr.toFilled('x')(base);
|
|
321
350
|
*
|
|
322
351
|
* assert.deepStrictEqual(filled, [0, 0, 0]);
|
|
352
|
+
*
|
|
323
353
|
* assert.deepStrictEqual(filledCurried, ['x', 'x', 'x']);
|
|
324
354
|
* ```
|
|
325
355
|
*/
|
|
@@ -349,10 +379,13 @@ export function toFilled<E>(
|
|
|
349
379
|
switch (args.length) {
|
|
350
380
|
case 2: {
|
|
351
381
|
const [array, value] = args;
|
|
382
|
+
|
|
352
383
|
return create(asPositiveUint32(array.length), value);
|
|
353
384
|
}
|
|
385
|
+
|
|
354
386
|
case 1: {
|
|
355
387
|
const [value] = args;
|
|
388
|
+
|
|
356
389
|
return (array) => toFilled(array, value);
|
|
357
390
|
}
|
|
358
391
|
}
|
|
@@ -367,9 +400,11 @@ export function toFilled<E>(
|
|
|
367
400
|
* const base = [0, 1, 2, 3, 4];
|
|
368
401
|
*
|
|
369
402
|
* const filledMiddle = Arr.toRangeFilled(base, 9, [1, 4]);
|
|
403
|
+
*
|
|
370
404
|
* const filledPrefix = Arr.toRangeFilled(8, [0, 2])(base);
|
|
371
405
|
*
|
|
372
406
|
* assert.deepStrictEqual(filledMiddle, [0, 9, 9, 9, 4]);
|
|
407
|
+
*
|
|
373
408
|
* assert.deepStrictEqual(filledPrefix, [8, 8, 2, 3, 4]);
|
|
374
409
|
* ```
|
|
375
410
|
*/
|
|
@@ -422,12 +457,17 @@ export function toRangeFilled<E, const V>(
|
|
|
422
457
|
switch (args.length) {
|
|
423
458
|
case 3: {
|
|
424
459
|
const [array, value, [start, end]] = args;
|
|
460
|
+
|
|
425
461
|
const mut_cp: (E | V)[] = castMutable(copy(array));
|
|
462
|
+
|
|
426
463
|
mut_cp.fill(value, start, end);
|
|
464
|
+
|
|
427
465
|
return mut_cp;
|
|
428
466
|
}
|
|
467
|
+
|
|
429
468
|
case 2: {
|
|
430
469
|
const [value, fillRange] = args;
|
|
470
|
+
|
|
431
471
|
return (array) => toRangeFilled(array, value, fillRange);
|
|
432
472
|
}
|
|
433
473
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
describe('Arr modifications', () => {
|
|
15
15
|
describe(toUpdated, () => {
|
|
16
16
|
const xs = [1, 2, 3] as const;
|
|
17
|
+
|
|
17
18
|
const result = toUpdated(xs, 1, (x) => x + 2);
|
|
18
19
|
|
|
19
20
|
expectType<typeof result, ArrayOfLength<3, number>>('=');
|
|
@@ -21,6 +22,14 @@ describe('Arr modifications', () => {
|
|
|
21
22
|
test('case 1', () => {
|
|
22
23
|
assert.deepStrictEqual(result, [1, 4, 3]);
|
|
23
24
|
});
|
|
25
|
+
|
|
26
|
+
test('should work with curried version', () => {
|
|
27
|
+
const updater = toUpdated(1, (x: number) => x * 2);
|
|
28
|
+
|
|
29
|
+
const r = updater([10, 20, 30]);
|
|
30
|
+
|
|
31
|
+
assert.deepStrictEqual(r, [10, 40, 30]);
|
|
32
|
+
});
|
|
24
33
|
});
|
|
25
34
|
|
|
26
35
|
describe(toInserted, () => {
|
|
@@ -53,11 +62,20 @@ describe('Arr modifications', () => {
|
|
|
53
62
|
|
|
54
63
|
assert.deepStrictEqual(result, ['a', 'b', 'c', 5]);
|
|
55
64
|
});
|
|
65
|
+
|
|
66
|
+
test('should work with curried version', () => {
|
|
67
|
+
const inserter = toInserted(2, 99);
|
|
68
|
+
|
|
69
|
+
const result = inserter([1, 2, 3]);
|
|
70
|
+
|
|
71
|
+
assert.deepStrictEqual(result, [1, 2, 99, 3]);
|
|
72
|
+
});
|
|
56
73
|
});
|
|
57
74
|
|
|
58
75
|
describe(toRemoved, () => {
|
|
59
76
|
test('case 1', () => {
|
|
60
77
|
const xs = [1, 2, 3] as const;
|
|
78
|
+
|
|
61
79
|
const result = toRemoved(xs, 1);
|
|
62
80
|
|
|
63
81
|
expectType<typeof result, readonly (1 | 2 | 3)[]>('=');
|
|
@@ -67,6 +85,7 @@ describe('Arr modifications', () => {
|
|
|
67
85
|
|
|
68
86
|
test('case 2 (remove head)', () => {
|
|
69
87
|
const xs = [1, 2, 3] as const;
|
|
88
|
+
|
|
70
89
|
const result = toRemoved(xs, 0);
|
|
71
90
|
|
|
72
91
|
expectType<typeof result, readonly (1 | 2 | 3)[]>('=');
|
|
@@ -76,6 +95,7 @@ describe('Arr modifications', () => {
|
|
|
76
95
|
|
|
77
96
|
test('case 3 (remove tail)', () => {
|
|
78
97
|
const xs = [1, 2, 3] as const;
|
|
98
|
+
|
|
79
99
|
const result = toRemoved(xs, 2);
|
|
80
100
|
|
|
81
101
|
expectType<typeof result, readonly (1 | 2 | 3)[]>('=');
|
|
@@ -85,17 +105,27 @@ describe('Arr modifications', () => {
|
|
|
85
105
|
|
|
86
106
|
test('case 4 (number[])', () => {
|
|
87
107
|
const xs: number[] = [1, 2, 3];
|
|
108
|
+
|
|
88
109
|
const result = toRemoved(xs, 5);
|
|
89
110
|
|
|
90
111
|
expectType<typeof result, readonly number[]>('=');
|
|
91
112
|
|
|
92
113
|
assert.deepStrictEqual(result, [1, 2, 3]);
|
|
93
114
|
});
|
|
115
|
+
|
|
116
|
+
test('should work with curried version', () => {
|
|
117
|
+
const removeFirst = toRemoved(0);
|
|
118
|
+
|
|
119
|
+
const result = removeFirst([10, 20, 30]);
|
|
120
|
+
|
|
121
|
+
assert.deepStrictEqual(result, [20, 30]);
|
|
122
|
+
});
|
|
94
123
|
});
|
|
95
124
|
|
|
96
125
|
describe(toPushed, () => {
|
|
97
126
|
test('case 1', () => {
|
|
98
127
|
const xs = [1, 2, 3] as const;
|
|
128
|
+
|
|
99
129
|
const result = toPushed(xs, 4 as const);
|
|
100
130
|
|
|
101
131
|
expectType<typeof result, readonly [1, 2, 3, 4]>('=');
|
|
@@ -105,12 +135,21 @@ describe('Arr modifications', () => {
|
|
|
105
135
|
|
|
106
136
|
test('case 2', () => {
|
|
107
137
|
const xs: number[] = [1, 2, 3];
|
|
138
|
+
|
|
108
139
|
const result = toPushed(xs, 4 as const);
|
|
109
140
|
|
|
110
141
|
expectType<typeof result, readonly [...number[], 4]>('=');
|
|
111
142
|
|
|
112
143
|
assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
113
144
|
});
|
|
145
|
+
|
|
146
|
+
test('should work with curried version', () => {
|
|
147
|
+
const pushFive = toPushed(5);
|
|
148
|
+
|
|
149
|
+
const result = pushFive([1, 2, 3]);
|
|
150
|
+
|
|
151
|
+
assert.deepStrictEqual(result, [1, 2, 3, 5]);
|
|
152
|
+
});
|
|
114
153
|
});
|
|
115
154
|
|
|
116
155
|
describe(toUnshifted, () => {
|
|
@@ -133,11 +172,20 @@ describe('Arr modifications', () => {
|
|
|
133
172
|
|
|
134
173
|
assert.deepStrictEqual(result, [4, 1, 2, 3]);
|
|
135
174
|
});
|
|
175
|
+
|
|
176
|
+
test('should work with curried version', () => {
|
|
177
|
+
const unshiftZero = toUnshifted(0);
|
|
178
|
+
|
|
179
|
+
const result = unshiftZero([1, 2, 3]);
|
|
180
|
+
|
|
181
|
+
assert.deepStrictEqual(result, [0, 1, 2, 3]);
|
|
182
|
+
});
|
|
136
183
|
});
|
|
137
184
|
|
|
138
185
|
describe(toFilled, () => {
|
|
139
186
|
test('should fill entire array with value', () => {
|
|
140
187
|
const arr = [1, 2, 3, 4, 5];
|
|
188
|
+
|
|
141
189
|
const result = toFilled(arr, 0);
|
|
142
190
|
|
|
143
191
|
assert.deepStrictEqual(result, [0, 0, 0, 0, 0]);
|
|
@@ -145,7 +193,9 @@ describe('Arr modifications', () => {
|
|
|
145
193
|
|
|
146
194
|
test('should work with curried version', () => {
|
|
147
195
|
const fillWithZero = toFilled(0);
|
|
196
|
+
|
|
148
197
|
const arr = [1, 2, 3];
|
|
198
|
+
|
|
149
199
|
const result = fillWithZero(arr);
|
|
150
200
|
|
|
151
201
|
assert.deepStrictEqual(result, [0, 0, 0]);
|
|
@@ -155,6 +205,7 @@ describe('Arr modifications', () => {
|
|
|
155
205
|
describe(toRangeFilled, () => {
|
|
156
206
|
test('should fill array with range', () => {
|
|
157
207
|
const arr = [1, 2, 3, 4, 5];
|
|
208
|
+
|
|
158
209
|
const result = toRangeFilled(arr, 0, [1, 4]);
|
|
159
210
|
|
|
160
211
|
assert.deepStrictEqual(result, [1, 0, 0, 0, 5]);
|
|
@@ -162,6 +213,7 @@ describe('Arr modifications', () => {
|
|
|
162
213
|
|
|
163
214
|
test('should fill with range starting from 0', () => {
|
|
164
215
|
const arr = [1, 2, 3, 4, 5];
|
|
216
|
+
|
|
165
217
|
const result = toRangeFilled(arr, 9, [0, 3]);
|
|
166
218
|
|
|
167
219
|
assert.deepStrictEqual(result, [9, 9, 9, 4, 5]);
|
|
@@ -169,6 +221,7 @@ describe('Arr modifications', () => {
|
|
|
169
221
|
|
|
170
222
|
test('should handle empty range', () => {
|
|
171
223
|
const arr = [1, 2, 3];
|
|
224
|
+
|
|
172
225
|
const result = toRangeFilled(arr, 0, [2, 2]);
|
|
173
226
|
|
|
174
227
|
assert.deepStrictEqual(result, [1, 2, 3]);
|
|
@@ -176,6 +229,7 @@ describe('Arr modifications', () => {
|
|
|
176
229
|
|
|
177
230
|
test('should clamp range to array bounds', () => {
|
|
178
231
|
const arr = [1, 2, 3];
|
|
232
|
+
|
|
179
233
|
const result = toRangeFilled(arr, 0, [1, 10]);
|
|
180
234
|
|
|
181
235
|
assert.deepStrictEqual(result, [1, 0, 0]);
|
|
@@ -183,11 +237,20 @@ describe('Arr modifications', () => {
|
|
|
183
237
|
|
|
184
238
|
test('should handle negative start (clamped to 0)', () => {
|
|
185
239
|
const arr = [1, 2, 3];
|
|
240
|
+
|
|
186
241
|
const result = toRangeFilled(arr, 9, [-5, 2]);
|
|
187
242
|
|
|
188
243
|
assert.deepStrictEqual(result, [9, 9, 3]);
|
|
189
244
|
});
|
|
190
245
|
|
|
246
|
+
test('should work with curried version', () => {
|
|
247
|
+
const fillMiddle = toRangeFilled(7, [1, 3]);
|
|
248
|
+
|
|
249
|
+
const result = fillMiddle([1, 2, 3, 4]);
|
|
250
|
+
|
|
251
|
+
assert.deepStrictEqual(result, [1, 7, 7, 4]);
|
|
252
|
+
});
|
|
253
|
+
|
|
191
254
|
test('A non-integer starting value should result in a type error', () => {
|
|
192
255
|
const arr = [1, 2, 3];
|
|
193
256
|
|
|
@@ -214,7 +277,9 @@ describe('Arr modifications', () => {
|
|
|
214
277
|
|
|
215
278
|
test('should work with different value types', () => {
|
|
216
279
|
const nums = [1, 2, 3] as const;
|
|
280
|
+
|
|
217
281
|
const withString = set(nums, 1, 'two');
|
|
282
|
+
|
|
218
283
|
expectType<typeof withString, readonly [1 | 'two', 2 | 'two', 3 | 'two']>(
|
|
219
284
|
'=',
|
|
220
285
|
);
|
|
@@ -224,6 +289,7 @@ describe('Arr modifications', () => {
|
|
|
224
289
|
|
|
225
290
|
test('should work at index 0', () => {
|
|
226
291
|
const tuple = ['a', 'b', 'c'] as const;
|
|
292
|
+
|
|
227
293
|
const updated = set(tuple, 0, 'A');
|
|
228
294
|
|
|
229
295
|
assert.deepStrictEqual(updated, ['A', 'b', 'c']);
|
|
@@ -231,9 +297,18 @@ describe('Arr modifications', () => {
|
|
|
231
297
|
|
|
232
298
|
test('should work at last index', () => {
|
|
233
299
|
const tuple = ['a', 'b', 'c'] as const;
|
|
300
|
+
|
|
234
301
|
const updated = set(tuple, 2, 'C');
|
|
235
302
|
|
|
236
303
|
assert.deepStrictEqual(updated, ['a', 'b', 'C']);
|
|
237
304
|
});
|
|
305
|
+
|
|
306
|
+
test('should work with curried version', () => {
|
|
307
|
+
const setIndex1To99 = set(1, 99);
|
|
308
|
+
|
|
309
|
+
const r = setIndex1To99([10, 20, 30]);
|
|
310
|
+
|
|
311
|
+
assert.deepStrictEqual(r, [10, 99, 30]);
|
|
312
|
+
});
|
|
238
313
|
});
|
|
239
314
|
});
|