ts-data-forge 5.0.1 → 5.1.1
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 +101 -50
- 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 +6 -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.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +34 -10
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +34 -4
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +20 -7
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +20 -7
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +5 -2
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +5 -2
- 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 +17 -2
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +9 -2
- 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 +6 -0
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +35 -18
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +25 -14
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +35 -15
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +5 -3
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +46 -19
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +9 -2
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +48 -19
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +9 -2
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +65 -25
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +13 -5
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +60 -25
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +12 -5
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -1
- package/dist/functional/match.d.mts +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 +3 -2
- 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-none.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +4 -2
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +4 -2
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +2 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +2 -1
- 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 +4 -2
- package/dist/functional/optional/impl/optional-none.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +4 -2
- 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 +5 -3
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +4 -2
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +7 -4
- 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 +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +4 -2
- 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 +3 -1
- package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +3 -1
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +2 -2
- package/dist/functional/result/impl/result-err.d.mts +4 -2
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +3 -1
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +3 -2
- 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 +4 -1
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +4 -1
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +3 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +3 -1
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +4 -2
- package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +4 -2
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +4 -2
- package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +4 -2
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts +7 -3
- package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +7 -3
- 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 +4 -2
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +3 -1
- 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 +7 -4
- 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 +3 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +3 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +3 -2
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +3 -2
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +7 -4
- 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 +3 -2
- 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 +3 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +3 -1
- 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 +3 -2
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +2 -1
- 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 +3 -1
- 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 +3 -1
- 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 +3 -1
- 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 +3 -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 +7 -3
- 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 +7 -3
- 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 +12 -1
- package/dist/guard/has-key.d.mts +6 -3
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +2 -2
- 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 +3 -2
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +3 -2
- 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 +42 -21
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +42 -21
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +33 -19
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +33 -19
- 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 +34 -20
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +34 -20
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +47 -26
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +48 -27
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +48 -27
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +50 -29
- 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 +31 -19
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +31 -19
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/num.d.mts +29 -20
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +24 -17
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +33 -11
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +33 -11
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +12 -3
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +10 -3
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/tuple.d.mts +14 -3
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +14 -3
- 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.map +1 -1
- package/dist/promise/promise.d.mts +8 -4
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +8 -4
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +26 -28
- package/src/array/impl/array-utils-creation.mts +20 -0
- package/src/array/impl/array-utils-creation.test.mts +72 -1
- package/src/array/impl/array-utils-element-access.mts +13 -0
- package/src/array/impl/array-utils-element-access.test.mts +36 -15
- package/src/array/impl/array-utils-iterators.test.mts +17 -0
- package/src/array/impl/array-utils-modification.mts +78 -19
- 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 +61 -16
- package/src/array/impl/array-utils-reducing-value.test.mts +107 -25
- package/src/array/impl/array-utils-search.mts +57 -4
- package/src/array/impl/array-utils-search.test.mts +61 -10
- package/src/array/impl/array-utils-set-op.mts +26 -7
- package/src/array/impl/array-utils-set-op.test.mts +129 -13
- package/src/array/impl/array-utils-size.mts +5 -2
- 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 +29 -2
- 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 +115 -3
- package/src/array/impl/array-utils-validation.mts +41 -18
- package/src/array/impl/array-utils-validation.test.mts +176 -78
- package/src/array/impl/array.test.mts +18 -6
- package/src/collections/imap-mapped.mts +11 -0
- package/src/collections/imap-mapped.test.mts +86 -18
- package/src/collections/imap.mts +47 -15
- package/src/collections/imap.test.mts +137 -31
- package/src/collections/iset-mapped.mts +54 -19
- package/src/collections/iset-mapped.test.mts +163 -52
- package/src/collections/iset.mts +53 -19
- package/src/collections/iset.test.mts +323 -130
- package/src/collections/queue.mts +78 -25
- package/src/collections/queue.test.mts +65 -35
- package/src/collections/stack.mts +67 -25
- package/src/collections/stack.test.mts +59 -15
- package/src/functional/match.mts +17 -1
- package/src/functional/match.test.mts +2 -0
- package/src/functional/optional/impl/optional-expect-to-be.mts +5 -2
- 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-none.mts +1 -1
- package/src/functional/optional/impl/optional-is-optional.mts +4 -2
- package/src/functional/optional/impl/optional-is-some.mts +2 -1
- package/src/functional/optional/impl/optional-map.mts +5 -0
- package/src/functional/optional/impl/optional-none.mts +4 -2
- package/src/functional/optional/impl/optional-or-else.mts +6 -0
- package/src/functional/optional/impl/optional-some.mts +5 -3
- package/src/functional/optional/impl/optional-to-nullable.mts +4 -2
- package/src/functional/optional/impl/optional-unwrap-or.mts +9 -4
- package/src/functional/optional/impl/optional-unwrap-throw.mts +2 -1
- package/src/functional/optional/impl/optional-unwrap.mts +4 -2
- package/src/functional/optional/impl/optional-zip.mts +3 -1
- package/src/functional/optional.test.mts +126 -54
- package/src/functional/pipe.mts +2 -2
- package/src/functional/pipe.test.mts +7 -4
- package/src/functional/result/impl/result-err.mts +4 -2
- package/src/functional/result/impl/result-expect-to-be.mts +5 -2
- 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 +4 -1
- package/src/functional/result/impl/result-from-throwable.mts +5 -1
- package/src/functional/result/impl/result-is-err.mts +4 -2
- package/src/functional/result/impl/result-is-ok.mts +4 -2
- package/src/functional/result/impl/result-is-result.mts +7 -3
- 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 +4 -2
- 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 +9 -4
- package/src/functional/result/impl/result-unwrap-err-throw.mts +3 -1
- package/src/functional/result/impl/result-unwrap-err.mts +3 -2
- package/src/functional/result/impl/result-unwrap-ok-or.mts +9 -4
- package/src/functional/result/impl/result-unwrap-ok.mts +4 -2
- package/src/functional/result/impl/result-unwrap-throw.mts +3 -1
- package/src/functional/result/impl/result-zip.mts +3 -1
- package/src/functional/result.test.mts +182 -152
- package/src/functional/ternary-result/impl/ternary-result-err.mts +3 -2
- 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 +3 -1
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +4 -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 +7 -3
- 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 +99 -8
- package/src/globals.d.mts +12 -1
- package/src/guard/has-key.mts +8 -5
- package/src/guard/has-key.test.mts +9 -5
- package/src/guard/is-error.test.mts +143 -0
- package/src/guard/is-non-empty-string.test.mts +44 -24
- package/src/guard/is-non-null-object.test.mts +45 -26
- package/src/guard/is-primitive.test.mts +51 -28
- package/src/guard/is-record.mts +34 -0
- package/src/guard/is-record.test.mts +28 -7
- package/src/guard/is-type.mts +3 -0
- package/src/guard/is-type.test.mts +285 -155
- package/src/guard/key-is-in.mts +3 -2
- package/src/guard/key-is-in.test.mts +2 -2
- package/src/iterator/range.mts +9 -0
- package/src/json/json.mts +50 -21
- package/src/json/json.test.mts +224 -176
- package/src/number/branded-types/finite-number.test.mts +51 -11
- package/src/number/branded-types/int.mts +33 -19
- package/src/number/branded-types/int.test.mts +56 -14
- package/src/number/branded-types/int16.test.mts +63 -16
- package/src/number/branded-types/int32.test.mts +63 -16
- package/src/number/branded-types/non-negative-finite-number.test.mts +52 -12
- package/src/number/branded-types/non-negative-int16.test.mts +59 -16
- package/src/number/branded-types/non-negative-int32.test.mts +59 -16
- package/src/number/branded-types/non-zero-finite-number.test.mts +65 -14
- package/src/number/branded-types/non-zero-int.test.mts +72 -19
- package/src/number/branded-types/non-zero-int16.test.mts +60 -16
- package/src/number/branded-types/non-zero-int32.test.mts +60 -16
- package/src/number/branded-types/non-zero-safe-int.mts +2 -2
- package/src/number/branded-types/non-zero-safe-int.test.mts +85 -23
- package/src/number/branded-types/non-zero-uint16.test.mts +53 -16
- package/src/number/branded-types/non-zero-uint32.test.mts +53 -16
- package/src/number/branded-types/positive-finite-number.test.mts +59 -14
- package/src/number/branded-types/positive-int.mts +34 -20
- package/src/number/branded-types/positive-int.test.mts +64 -17
- package/src/number/branded-types/positive-int16.test.mts +50 -15
- package/src/number/branded-types/positive-int32.test.mts +50 -15
- package/src/number/branded-types/positive-safe-int.mts +48 -27
- package/src/number/branded-types/positive-safe-int.test.mts +68 -19
- package/src/number/branded-types/positive-uint16.test.mts +53 -16
- package/src/number/branded-types/positive-uint32.test.mts +53 -16
- package/src/number/branded-types/safe-int.mts +50 -29
- package/src/number/branded-types/safe-int.test.mts +70 -18
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/branded-types/safe-uint.test.mts +65 -17
- package/src/number/branded-types/uint.mts +31 -19
- package/src/number/branded-types/uint.test.mts +58 -15
- package/src/number/branded-types/uint16.test.mts +56 -15
- package/src/number/branded-types/uint32.test.mts +56 -15
- package/src/number/enum/int8.test.mts +7 -1
- package/src/number/enum/uint8.test.mts +7 -1
- package/src/number/num.mts +32 -21
- package/src/number/num.test.mts +88 -26
- package/src/number/refined-number-utils.mts +38 -13
- package/src/object/object.mts +19 -3
- package/src/object/object.test.mts +16 -6
- package/src/others/cast-mutable.test.mts +8 -1
- package/src/others/cast-readonly.test.mts +21 -4
- package/src/others/if-then.test.mts +40 -24
- 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 +14 -3
- package/src/others/unknown-to-string.mts +2 -0
- package/src/others/unknown-to-string.test.mts +10 -0
- package/src/promise/promise.mts +8 -4
- package/src/promise/promise.test.mts +8 -13
|
@@ -18,40 +18,45 @@ describe('Arr reducing value', () => {
|
|
|
18
18
|
describe(min, () => {
|
|
19
19
|
{
|
|
20
20
|
const xs = [3, 5, 4] as const;
|
|
21
|
+
|
|
21
22
|
const result = min(xs);
|
|
22
23
|
|
|
23
24
|
expectType<typeof result, Some<3 | 4 | 5>>('=');
|
|
24
25
|
|
|
25
26
|
test('case 1', () => {
|
|
26
|
-
|
|
27
|
+
assert.isTrue(Optional.isSome(result));
|
|
27
28
|
|
|
28
29
|
if (Optional.isSome(result)) {
|
|
29
30
|
expect(result.value).toBe(3);
|
|
30
31
|
}
|
|
31
32
|
});
|
|
32
33
|
}
|
|
34
|
+
|
|
33
35
|
{
|
|
34
36
|
const xs = [3, 5, 4] as const;
|
|
37
|
+
|
|
35
38
|
const result = min(xs, (a, b) => a - b);
|
|
36
39
|
|
|
37
40
|
expectType<typeof result, Some<3 | 4 | 5>>('=');
|
|
38
41
|
|
|
39
42
|
test('case 2', () => {
|
|
40
|
-
|
|
43
|
+
assert.isTrue(Optional.isSome(result));
|
|
41
44
|
|
|
42
45
|
if (Optional.isSome(result)) {
|
|
43
46
|
expect(result.value).toBe(3);
|
|
44
47
|
}
|
|
45
48
|
});
|
|
46
49
|
}
|
|
50
|
+
|
|
47
51
|
{
|
|
48
52
|
const xs: readonly (3 | 4 | 5)[] = [3, 5, 4] as const;
|
|
53
|
+
|
|
49
54
|
const result = min(xs, (a, b) => a - b);
|
|
50
55
|
|
|
51
56
|
expectType<typeof result, Optional<3 | 4 | 5>>('=');
|
|
52
57
|
|
|
53
58
|
test('case 3', () => {
|
|
54
|
-
|
|
59
|
+
assert.isTrue(Optional.isSome(result));
|
|
55
60
|
|
|
56
61
|
if (Optional.isSome(result)) {
|
|
57
62
|
expect(result.value).toBe(3);
|
|
@@ -62,12 +67,13 @@ describe('Arr reducing value', () => {
|
|
|
62
67
|
|
|
63
68
|
describe(max, () => {
|
|
64
69
|
const xs = [3, 5, 4] as const;
|
|
70
|
+
|
|
65
71
|
const result = max(xs, (a, b) => a - b);
|
|
66
72
|
|
|
67
73
|
expectType<typeof result, Some<3 | 4 | 5>>('=');
|
|
68
74
|
|
|
69
75
|
test('case 1', () => {
|
|
70
|
-
|
|
76
|
+
assert.isTrue(Optional.isSome(result));
|
|
71
77
|
|
|
72
78
|
if (Optional.isSome(result)) {
|
|
73
79
|
expect(result.value).toBe(5);
|
|
@@ -76,9 +82,10 @@ describe('Arr reducing value', () => {
|
|
|
76
82
|
|
|
77
83
|
test('case 2: no comparator', () => {
|
|
78
84
|
const res = max(xs);
|
|
85
|
+
|
|
79
86
|
expectType<typeof res, Some<3 | 4 | 5>>('=');
|
|
80
87
|
|
|
81
|
-
|
|
88
|
+
assert.isTrue(Optional.isSome(res));
|
|
82
89
|
|
|
83
90
|
if (Optional.isSome(res)) {
|
|
84
91
|
expect(res.value).toBe(5);
|
|
@@ -87,10 +94,12 @@ describe('Arr reducing value', () => {
|
|
|
87
94
|
|
|
88
95
|
test('case 3: readonly array', () => {
|
|
89
96
|
const arr: readonly number[] = [1, 5, 2];
|
|
97
|
+
|
|
90
98
|
const res = max(arr);
|
|
99
|
+
|
|
91
100
|
expectType<typeof res, Optional<number>>('=');
|
|
92
101
|
|
|
93
|
-
|
|
102
|
+
assert.isTrue(Optional.isSome(res));
|
|
94
103
|
|
|
95
104
|
if (Optional.isSome(res)) {
|
|
96
105
|
expect(res.value).toBe(5);
|
|
@@ -99,10 +108,12 @@ describe('Arr reducing value', () => {
|
|
|
99
108
|
|
|
100
109
|
test('case 4: empty array', () => {
|
|
101
110
|
const arr: readonly number[] = [];
|
|
111
|
+
|
|
102
112
|
const res = max(arr);
|
|
113
|
+
|
|
103
114
|
expectType<typeof res, Optional<number>>('=');
|
|
104
115
|
|
|
105
|
-
|
|
116
|
+
assert.isTrue(Optional.isNone(res));
|
|
106
117
|
});
|
|
107
118
|
});
|
|
108
119
|
|
|
@@ -133,7 +144,7 @@ describe('Arr reducing value', () => {
|
|
|
133
144
|
>('=');
|
|
134
145
|
|
|
135
146
|
test('case 1', () => {
|
|
136
|
-
|
|
147
|
+
assert.isTrue(Optional.isSome(result));
|
|
137
148
|
|
|
138
149
|
if (Optional.isSome(result)) {
|
|
139
150
|
assert.deepStrictEqual(result.value, { x: 1, y: 2 });
|
|
@@ -142,10 +153,12 @@ describe('Arr reducing value', () => {
|
|
|
142
153
|
|
|
143
154
|
test('case 2: empty array', () => {
|
|
144
155
|
const arr: readonly { x: number }[] = [];
|
|
156
|
+
|
|
145
157
|
const res = minBy(arr, (a) => a.x);
|
|
158
|
+
|
|
146
159
|
expectType<typeof res, Optional<{ x: number }>>('=');
|
|
147
160
|
|
|
148
|
-
|
|
161
|
+
assert.isTrue(Optional.isNone(res));
|
|
149
162
|
});
|
|
150
163
|
|
|
151
164
|
test('case 3: custom comparator', () => {
|
|
@@ -172,7 +185,7 @@ describe('Arr reducing value', () => {
|
|
|
172
185
|
>
|
|
173
186
|
>('=');
|
|
174
187
|
|
|
175
|
-
|
|
188
|
+
assert.isTrue(Optional.isSome(res));
|
|
176
189
|
|
|
177
190
|
if (Optional.isSome(res)) {
|
|
178
191
|
assert.deepStrictEqual(res.value, { name: 'apple', score: 10 });
|
|
@@ -207,7 +220,7 @@ describe('Arr reducing value', () => {
|
|
|
207
220
|
>('=');
|
|
208
221
|
|
|
209
222
|
test('case 1', () => {
|
|
210
|
-
|
|
223
|
+
assert.isTrue(Optional.isSome(result));
|
|
211
224
|
|
|
212
225
|
if (Optional.isSome(result)) {
|
|
213
226
|
assert.deepStrictEqual(result.value, { x: 6, y: 1 });
|
|
@@ -216,10 +229,12 @@ describe('Arr reducing value', () => {
|
|
|
216
229
|
|
|
217
230
|
test('case 2: empty array', () => {
|
|
218
231
|
const arr: readonly { x: number }[] = [];
|
|
232
|
+
|
|
219
233
|
const res = maxBy(arr, (a) => a.x);
|
|
234
|
+
|
|
220
235
|
expectType<typeof res, Optional<{ x: number }>>('=');
|
|
221
236
|
|
|
222
|
-
|
|
237
|
+
assert.isTrue(Optional.isNone(res));
|
|
223
238
|
});
|
|
224
239
|
|
|
225
240
|
test('case 3: custom comparator', () => {
|
|
@@ -246,7 +261,7 @@ describe('Arr reducing value', () => {
|
|
|
246
261
|
>
|
|
247
262
|
>('=');
|
|
248
263
|
|
|
249
|
-
|
|
264
|
+
assert.isTrue(Optional.isSome(res));
|
|
250
265
|
|
|
251
266
|
if (Optional.isSome(res)) {
|
|
252
267
|
assert.deepStrictEqual(res.value, { name: 'cherry', score: 12 });
|
|
@@ -274,11 +289,21 @@ describe('Arr reducing value', () => {
|
|
|
274
289
|
|
|
275
290
|
test('case 2: empty array', () => {
|
|
276
291
|
const arr: readonly number[] = [];
|
|
292
|
+
|
|
277
293
|
const res = count(arr, (x) => x > 0);
|
|
294
|
+
|
|
278
295
|
expectType<typeof res, Uint32>('=');
|
|
279
296
|
|
|
280
297
|
expect(res).toBe(0);
|
|
281
298
|
});
|
|
299
|
+
|
|
300
|
+
test('should work with curried version', () => {
|
|
301
|
+
const countEven = count((x: number) => x % 2 === 0);
|
|
302
|
+
|
|
303
|
+
const res = countEven([1, 2, 3, 4, 5, 6]);
|
|
304
|
+
|
|
305
|
+
expect(res).toBe(3);
|
|
306
|
+
});
|
|
282
307
|
});
|
|
283
308
|
|
|
284
309
|
describe(countBy, () => {
|
|
@@ -308,16 +333,41 @@ describe('Arr reducing value', () => {
|
|
|
308
333
|
|
|
309
334
|
test('case 2: empty array', () => {
|
|
310
335
|
const arr: readonly { x: number }[] = [];
|
|
336
|
+
|
|
311
337
|
const res = countBy(arr, (a) => a.x);
|
|
338
|
+
|
|
312
339
|
expectType<typeof res, IMap<number, Uint32>>('=');
|
|
313
340
|
|
|
314
341
|
expect(res.size).toBe(0);
|
|
315
342
|
});
|
|
343
|
+
|
|
344
|
+
test('should work with curried version', () => {
|
|
345
|
+
const groupByParity = countBy((x: number) => x % 2);
|
|
346
|
+
|
|
347
|
+
const res = groupByParity([1, 2, 3, 4, 5, 6]);
|
|
348
|
+
|
|
349
|
+
const even = res.get(0);
|
|
350
|
+
|
|
351
|
+
assert.isTrue(Optional.isSome(even));
|
|
352
|
+
|
|
353
|
+
if (Optional.isSome(even)) {
|
|
354
|
+
expect(even.value).toBe(3);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const odd = res.get(1);
|
|
358
|
+
|
|
359
|
+
assert.isTrue(Optional.isSome(odd));
|
|
360
|
+
|
|
361
|
+
if (Optional.isSome(odd)) {
|
|
362
|
+
expect(odd.value).toBe(3);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
316
365
|
});
|
|
317
366
|
|
|
318
367
|
describe(foldl, () => {
|
|
319
368
|
test('empty array', () => {
|
|
320
369
|
const result = foldl([], (acc, curr: number) => acc + curr, 0);
|
|
370
|
+
|
|
321
371
|
expectType<typeof result, number>('=');
|
|
322
372
|
|
|
323
373
|
expect(result).toBe(0);
|
|
@@ -325,6 +375,7 @@ describe('Arr reducing value', () => {
|
|
|
325
375
|
|
|
326
376
|
test('sum numbers', () => {
|
|
327
377
|
const result = foldl([1, 2, 3] as const, (acc, curr) => acc + curr, 0);
|
|
378
|
+
|
|
328
379
|
expectType<typeof result, number>('=');
|
|
329
380
|
|
|
330
381
|
expect(result).toBe(6);
|
|
@@ -336,15 +387,25 @@ describe('Arr reducing value', () => {
|
|
|
336
387
|
(acc, curr) => acc + curr,
|
|
337
388
|
'',
|
|
338
389
|
);
|
|
390
|
+
|
|
339
391
|
expectType<typeof result, string>('=');
|
|
340
392
|
|
|
341
393
|
expect(result).toBe('abc');
|
|
342
394
|
});
|
|
395
|
+
|
|
396
|
+
test('should work with curried version', () => {
|
|
397
|
+
const sumReduce = foldl((acc: number, curr: number) => acc + curr, 0);
|
|
398
|
+
|
|
399
|
+
const result = sumReduce([1, 2, 3, 4]);
|
|
400
|
+
|
|
401
|
+
expect(result).toBe(10);
|
|
402
|
+
});
|
|
343
403
|
});
|
|
344
404
|
|
|
345
405
|
describe(foldr, () => {
|
|
346
406
|
test('empty array', () => {
|
|
347
407
|
const result = foldr([], (acc, curr: number) => acc + curr, 0);
|
|
408
|
+
|
|
348
409
|
expectType<typeof result, number>('=');
|
|
349
410
|
|
|
350
411
|
expect(result).toBe(0);
|
|
@@ -353,6 +414,7 @@ describe('Arr reducing value', () => {
|
|
|
353
414
|
test('subtract numbers from right', () => {
|
|
354
415
|
// (1 - (2 - (3 - 0))) = 1 - (2 - 3) = 1 - (-1) = 2
|
|
355
416
|
const result = foldr([1, 2, 3] as const, (acc, curr) => curr - acc, 0);
|
|
417
|
+
|
|
356
418
|
expectType<typeof result, number>('=');
|
|
357
419
|
|
|
358
420
|
expect(result).toBe(2); // 3 - (2 - (1 - 0)) = 3 - (2 - 1) = 3 - 1 = 2. No, this is (acc, curr) => acc - curr.
|
|
@@ -369,6 +431,7 @@ describe('Arr reducing value', () => {
|
|
|
369
431
|
(acc, curr) => curr + acc,
|
|
370
432
|
'',
|
|
371
433
|
);
|
|
434
|
+
|
|
372
435
|
expectType<typeof result, string>('=');
|
|
373
436
|
|
|
374
437
|
expect(result).toBe('abc'); // c + (b + (a + "")) = cba. No, it's curr + acc.
|
|
@@ -376,11 +439,20 @@ describe('Arr reducing value', () => {
|
|
|
376
439
|
// Iteration 2: prev = "c", curr = "b". Result = "b" + "c" = "bc".
|
|
377
440
|
// Iteration 3: prev = "bc", curr = "a". Result = "a" + "bc" = "abc".
|
|
378
441
|
});
|
|
442
|
+
|
|
443
|
+
test('should work with curried version', () => {
|
|
444
|
+
const productReduce = foldr((acc: number, curr: number) => acc * curr, 1);
|
|
445
|
+
|
|
446
|
+
const result = productReduce([2, 3, 4]);
|
|
447
|
+
|
|
448
|
+
expect(result).toBe(24); // 1 * 4 * 3 * 2 = 24
|
|
449
|
+
});
|
|
379
450
|
});
|
|
380
451
|
|
|
381
452
|
describe(sum, () => {
|
|
382
453
|
test('empty array', () => {
|
|
383
454
|
const result = sum([]);
|
|
455
|
+
|
|
384
456
|
expectType<typeof result, 0>('=');
|
|
385
457
|
|
|
386
458
|
expect(result).toBe(0);
|
|
@@ -388,6 +460,7 @@ describe('Arr reducing value', () => {
|
|
|
388
460
|
|
|
389
461
|
test('one element array', () => {
|
|
390
462
|
const result = sum([23]);
|
|
463
|
+
|
|
391
464
|
expectType<typeof result, 23>('=');
|
|
392
465
|
|
|
393
466
|
expect(result).toBe(23);
|
|
@@ -395,6 +468,7 @@ describe('Arr reducing value', () => {
|
|
|
395
468
|
|
|
396
469
|
test('positive numbers', () => {
|
|
397
470
|
const result = sum([1, 2, 3, 4, 5] as const);
|
|
471
|
+
|
|
398
472
|
expectType<typeof result, number>('=');
|
|
399
473
|
|
|
400
474
|
expect(result).toBe(15);
|
|
@@ -402,6 +476,7 @@ describe('Arr reducing value', () => {
|
|
|
402
476
|
|
|
403
477
|
test('mixed numbers', () => {
|
|
404
478
|
const result = sum([1, -2, 3, 0, -5] as const);
|
|
479
|
+
|
|
405
480
|
expectType<typeof result, number>('=');
|
|
406
481
|
|
|
407
482
|
expect(result).toBe(-3);
|
|
@@ -411,35 +486,42 @@ describe('Arr reducing value', () => {
|
|
|
411
486
|
describe(join, () => {
|
|
412
487
|
test('should join array elements', () => {
|
|
413
488
|
const arr = ['Hello', 'World'];
|
|
489
|
+
|
|
414
490
|
const result = join(arr, ' ');
|
|
415
491
|
|
|
416
|
-
|
|
492
|
+
assert.isTrue(Result.isOk(result));
|
|
417
493
|
|
|
418
|
-
|
|
419
|
-
expect(result.value).toBe('Hello World');
|
|
420
|
-
}
|
|
494
|
+
expect(result.value).toBe('Hello World');
|
|
421
495
|
});
|
|
422
496
|
|
|
423
497
|
test('should handle empty separator', () => {
|
|
424
498
|
const arr = ['a', 'b', 'c'];
|
|
499
|
+
|
|
425
500
|
const result = join(arr, '');
|
|
426
501
|
|
|
427
|
-
|
|
502
|
+
assert.isTrue(Result.isOk(result));
|
|
428
503
|
|
|
429
|
-
|
|
430
|
-
expect(result.value).toBe('abc');
|
|
431
|
-
}
|
|
504
|
+
expect(result.value).toBe('abc');
|
|
432
505
|
});
|
|
433
506
|
|
|
434
507
|
test('should handle undefined separator', () => {
|
|
435
508
|
const arr = ['a', 'b', 'c'];
|
|
509
|
+
|
|
436
510
|
const result = join(arr);
|
|
437
511
|
|
|
438
|
-
|
|
512
|
+
assert.isTrue(Result.isOk(result));
|
|
439
513
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
514
|
+
expect(result.value).toBe('a,b,c');
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
test('should work with curried version', () => {
|
|
518
|
+
const joinWithDash = join('-');
|
|
519
|
+
|
|
520
|
+
const result = joinWithDash(['x', 'y', 'z']);
|
|
521
|
+
|
|
522
|
+
assert.isTrue(Result.isOk(result));
|
|
523
|
+
|
|
524
|
+
expect(result.value).toBe('x-y-z');
|
|
443
525
|
});
|
|
444
526
|
});
|
|
445
527
|
});
|
|
@@ -14,9 +14,11 @@ import { asUint32 } from '../../number/index.mjs';
|
|
|
14
14
|
* ];
|
|
15
15
|
*
|
|
16
16
|
* const found = Arr.find(users, (user) => user.id === 2);
|
|
17
|
+
*
|
|
17
18
|
* const missing = Arr.find<{ id: number }>((user) => user.id === 3)(users);
|
|
18
19
|
*
|
|
19
20
|
* assert.deepStrictEqual(found, Optional.some({ id: 2, name: 'Grace' }));
|
|
21
|
+
*
|
|
20
22
|
* assert.deepStrictEqual(missing, Optional.none);
|
|
21
23
|
* ```
|
|
22
24
|
*/
|
|
@@ -55,6 +57,7 @@ export function find<E>(
|
|
|
55
57
|
switch (args.length) {
|
|
56
58
|
case 2: {
|
|
57
59
|
const [array, predicate] = args;
|
|
60
|
+
|
|
58
61
|
const foundIndex = array.findIndex(
|
|
59
62
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
60
63
|
predicate as () => boolean,
|
|
@@ -75,6 +78,7 @@ export function find<E>(
|
|
|
75
78
|
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
76
79
|
Optional.some(array[foundIndex]!);
|
|
77
80
|
}
|
|
81
|
+
|
|
78
82
|
case 1: {
|
|
79
83
|
const [predicate] = args;
|
|
80
84
|
|
|
@@ -97,9 +101,11 @@ export function find<E>(
|
|
|
97
101
|
* const numbers = [1, 3, 2, 4, 5];
|
|
98
102
|
*
|
|
99
103
|
* const lastEven = Arr.findLast(numbers, (n) => n % 2 === 0);
|
|
104
|
+
*
|
|
100
105
|
* const none = Arr.findLast<number>((n) => n > 10)(numbers);
|
|
101
106
|
*
|
|
102
107
|
* assert.deepStrictEqual(lastEven, Optional.some(4));
|
|
108
|
+
*
|
|
103
109
|
* assert.deepStrictEqual(none, Optional.none);
|
|
104
110
|
* ```
|
|
105
111
|
*/
|
|
@@ -138,6 +144,7 @@ export function findLast<E>(
|
|
|
138
144
|
switch (args.length) {
|
|
139
145
|
case 2: {
|
|
140
146
|
const [array, predicate] = args;
|
|
147
|
+
|
|
141
148
|
const foundIndex = array.findLastIndex(
|
|
142
149
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
143
150
|
predicate as () => boolean,
|
|
@@ -158,6 +165,7 @@ export function findLast<E>(
|
|
|
158
165
|
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
159
166
|
Optional.some(array[foundIndex]!);
|
|
160
167
|
}
|
|
168
|
+
|
|
161
169
|
case 1: {
|
|
162
170
|
const [predicate] = args;
|
|
163
171
|
|
|
@@ -180,13 +188,15 @@ export function findLast<E>(
|
|
|
180
188
|
* const letters = ['a', 'b', 'c'];
|
|
181
189
|
*
|
|
182
190
|
* const indexOfB = Arr.findIndex(letters, (letter) => letter === 'b');
|
|
191
|
+
*
|
|
183
192
|
* // eslint-disable-next-line unicorn/prefer-array-index-of
|
|
184
193
|
* const indexOfMissing = Arr.findIndex<string>((letter) => letter === 'z')(
|
|
185
194
|
* letters,
|
|
186
195
|
* );
|
|
187
196
|
*
|
|
188
|
-
* assert(indexOfB === 1);
|
|
189
|
-
*
|
|
197
|
+
* assert.isTrue(indexOfB === 1);
|
|
198
|
+
*
|
|
199
|
+
* assert.isTrue(indexOfMissing === -1);
|
|
190
200
|
* ```
|
|
191
201
|
*/
|
|
192
202
|
export function findIndex<const Ar extends readonly unknown[]>(
|
|
@@ -219,6 +229,7 @@ export function findIndex<E>(
|
|
|
219
229
|
switch (args.length) {
|
|
220
230
|
case 2: {
|
|
221
231
|
const [array, predicate] = args;
|
|
232
|
+
|
|
222
233
|
return pipe(
|
|
223
234
|
array.findIndex(
|
|
224
235
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
@@ -226,8 +237,10 @@ export function findIndex<E>(
|
|
|
226
237
|
),
|
|
227
238
|
).map((idx) => (idx >= 0 ? asUint32(idx) : -1)).value;
|
|
228
239
|
}
|
|
240
|
+
|
|
229
241
|
case 1: {
|
|
230
242
|
const [predicate] = args;
|
|
243
|
+
|
|
231
244
|
return (array) => findIndex(array, predicate);
|
|
232
245
|
}
|
|
233
246
|
}
|
|
@@ -242,11 +255,13 @@ export function findIndex<E>(
|
|
|
242
255
|
* const letters = ['a', 'b', 'c', 'b'];
|
|
243
256
|
*
|
|
244
257
|
* const lastIndexOfB = Arr.findLastIndex(letters, (letter) => letter === 'b');
|
|
258
|
+
*
|
|
245
259
|
* // eslint-disable-next-line unicorn/prefer-array-index-of
|
|
246
260
|
* const notFound = Arr.findLastIndex<string>((letter) => letter === 'z')(letters);
|
|
247
261
|
*
|
|
248
|
-
* assert(lastIndexOfB === 3);
|
|
249
|
-
*
|
|
262
|
+
* assert.isTrue(lastIndexOfB === 3);
|
|
263
|
+
*
|
|
264
|
+
* assert.isTrue(notFound === -1);
|
|
250
265
|
* ```
|
|
251
266
|
*/
|
|
252
267
|
export function findLastIndex<const Ar extends readonly unknown[]>(
|
|
@@ -279,6 +294,7 @@ export function findLastIndex<E>(
|
|
|
279
294
|
switch (args.length) {
|
|
280
295
|
case 2: {
|
|
281
296
|
const [array, predicate] = args;
|
|
297
|
+
|
|
282
298
|
return pipe(
|
|
283
299
|
array.findLastIndex(
|
|
284
300
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
@@ -286,8 +302,10 @@ export function findLastIndex<E>(
|
|
|
286
302
|
),
|
|
287
303
|
).map((idx) => (idx >= 0 ? asUint32(idx) : -1)).value;
|
|
288
304
|
}
|
|
305
|
+
|
|
289
306
|
case 1: {
|
|
290
307
|
const [predicate] = args;
|
|
308
|
+
|
|
291
309
|
return (array) => findLastIndex(array, predicate);
|
|
292
310
|
}
|
|
293
311
|
}
|
|
@@ -302,14 +320,18 @@ export function findLastIndex<E>(
|
|
|
302
320
|
* const fruits = ['apple', 'banana', 'orange', 'banana'];
|
|
303
321
|
*
|
|
304
322
|
* const indexOfBanana = Arr.indexOf(fruits, 'banana');
|
|
323
|
+
*
|
|
305
324
|
* const indexOfGrape = Arr.indexOf(fruits, 'grape');
|
|
306
325
|
*
|
|
307
326
|
* // Curried version
|
|
308
327
|
* const findApple = Arr.indexOf('apple');
|
|
328
|
+
*
|
|
309
329
|
* const indexOfApple = findApple(fruits);
|
|
310
330
|
*
|
|
311
331
|
* console.log(indexOfBanana); // => 1
|
|
332
|
+
*
|
|
312
333
|
* console.log(indexOfGrape); // => -1
|
|
334
|
+
*
|
|
313
335
|
* console.log(indexOfApple); // => 0
|
|
314
336
|
* ```
|
|
315
337
|
*/
|
|
@@ -332,10 +354,13 @@ export function indexOf<E>(
|
|
|
332
354
|
const [array, searchElement] = args;
|
|
333
355
|
|
|
334
356
|
const index = array.indexOf(searchElement);
|
|
357
|
+
|
|
335
358
|
return index !== -1 ? asUint32(index) : -1;
|
|
336
359
|
}
|
|
360
|
+
|
|
337
361
|
case 1: {
|
|
338
362
|
const [searchElement] = args;
|
|
363
|
+
|
|
339
364
|
return (array) => indexOf(array, searchElement);
|
|
340
365
|
}
|
|
341
366
|
}
|
|
@@ -351,18 +376,24 @@ export function indexOf<E>(
|
|
|
351
376
|
*
|
|
352
377
|
* // Search for 'banana' starting from index 1
|
|
353
378
|
* const firstBanana = Arr.indexOfFrom(fruits, 'banana', 1);
|
|
379
|
+
*
|
|
354
380
|
* // Search for 'banana' starting from index 2
|
|
355
381
|
* const secondBanana = Arr.indexOfFrom(fruits, 'banana', 2);
|
|
382
|
+
*
|
|
356
383
|
* // Element not found
|
|
357
384
|
* const notFound = Arr.indexOfFrom(fruits, 'grape', 0);
|
|
358
385
|
*
|
|
359
386
|
* // Curried version
|
|
360
387
|
* const findBananaFrom2 = Arr.indexOfFrom('banana', 2);
|
|
388
|
+
*
|
|
361
389
|
* const index = findBananaFrom2(fruits);
|
|
362
390
|
*
|
|
363
391
|
* console.log(firstBanana); // => 1
|
|
392
|
+
*
|
|
364
393
|
* console.log(secondBanana); // => 3
|
|
394
|
+
*
|
|
365
395
|
* console.log(notFound); // => -1
|
|
396
|
+
*
|
|
366
397
|
* console.log(index); // => 3
|
|
367
398
|
* ```
|
|
368
399
|
*/
|
|
@@ -389,11 +420,15 @@ export function indexOfFrom<E>(
|
|
|
389
420
|
switch (args.length) {
|
|
390
421
|
case 3: {
|
|
391
422
|
const [array, searchElement, fromIndex] = args;
|
|
423
|
+
|
|
392
424
|
const index = array.indexOf(searchElement, fromIndex);
|
|
425
|
+
|
|
393
426
|
return index !== -1 ? asUint32(index) : -1;
|
|
394
427
|
}
|
|
428
|
+
|
|
395
429
|
case 2: {
|
|
396
430
|
const [searchElement, fromIndex] = args;
|
|
431
|
+
|
|
397
432
|
return (array) => indexOfFrom(array, searchElement, fromIndex);
|
|
398
433
|
}
|
|
399
434
|
}
|
|
@@ -408,16 +443,22 @@ export function indexOfFrom<E>(
|
|
|
408
443
|
* const fruits = ['apple', 'banana', 'orange', 'banana'];
|
|
409
444
|
*
|
|
410
445
|
* const lastBanana = Arr.lastIndexOf(fruits, 'banana');
|
|
446
|
+
*
|
|
411
447
|
* const lastApple = Arr.lastIndexOf(fruits, 'apple');
|
|
448
|
+
*
|
|
412
449
|
* const notFound = Arr.lastIndexOf(fruits, 'grape');
|
|
413
450
|
*
|
|
414
451
|
* // Curried version
|
|
415
452
|
* const findLastBanana = Arr.lastIndexOf('banana');
|
|
453
|
+
*
|
|
416
454
|
* const index = findLastBanana(fruits);
|
|
417
455
|
*
|
|
418
456
|
* console.log(lastBanana); // => 3
|
|
457
|
+
*
|
|
419
458
|
* console.log(lastApple); // => 0
|
|
459
|
+
*
|
|
420
460
|
* console.log(notFound); // => -1
|
|
461
|
+
*
|
|
421
462
|
* console.log(index); // => 3
|
|
422
463
|
* ```
|
|
423
464
|
*/
|
|
@@ -438,11 +479,15 @@ export function lastIndexOf<E>(
|
|
|
438
479
|
switch (args.length) {
|
|
439
480
|
case 2: {
|
|
440
481
|
const [array, searchElement] = args;
|
|
482
|
+
|
|
441
483
|
const index = array.lastIndexOf(searchElement);
|
|
484
|
+
|
|
442
485
|
return index !== -1 ? asUint32(index) : -1;
|
|
443
486
|
}
|
|
487
|
+
|
|
444
488
|
case 1: {
|
|
445
489
|
const [searchElement] = args;
|
|
490
|
+
|
|
446
491
|
return (array) => lastIndexOf(array, searchElement);
|
|
447
492
|
}
|
|
448
493
|
}
|
|
@@ -458,18 +503,24 @@ export function lastIndexOf<E>(
|
|
|
458
503
|
*
|
|
459
504
|
* // Search backwards for 'banana' from index 3
|
|
460
505
|
* const lastBananaFrom3 = Arr.lastIndexOfFrom(fruits, 'banana', 3);
|
|
506
|
+
*
|
|
461
507
|
* // Search backwards for 'banana' from index 2
|
|
462
508
|
* const lastBananaFrom2 = Arr.lastIndexOfFrom(fruits, 'banana', 2);
|
|
509
|
+
*
|
|
463
510
|
* // Element not found
|
|
464
511
|
* const notFound = Arr.lastIndexOfFrom(fruits, 'grape', 2);
|
|
465
512
|
*
|
|
466
513
|
* // Curried version
|
|
467
514
|
* const findBananaFrom3 = Arr.lastIndexOfFrom('banana', 3);
|
|
515
|
+
*
|
|
468
516
|
* const index = findBananaFrom3(fruits);
|
|
469
517
|
*
|
|
470
518
|
* console.log(lastBananaFrom3); // => 3
|
|
519
|
+
*
|
|
471
520
|
* console.log(lastBananaFrom2); // => 1
|
|
521
|
+
*
|
|
472
522
|
* console.log(notFound); // => -1
|
|
523
|
+
*
|
|
473
524
|
* console.log(index); // => 3
|
|
474
525
|
* ```
|
|
475
526
|
*/
|
|
@@ -501,8 +552,10 @@ export function lastIndexOfFrom<E>(
|
|
|
501
552
|
|
|
502
553
|
return index !== -1 ? asUint32(index) : -1;
|
|
503
554
|
}
|
|
555
|
+
|
|
504
556
|
case 2: {
|
|
505
557
|
const [searchElement, fromIndex] = args;
|
|
558
|
+
|
|
506
559
|
return (array) => lastIndexOfFrom(array, searchElement, fromIndex);
|
|
507
560
|
}
|
|
508
561
|
}
|