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
|
@@ -15,36 +15,48 @@ describe('ISet.create', () => {
|
|
|
15
15
|
const set = ISet.create<string>([]);
|
|
16
16
|
|
|
17
17
|
expect(set.size).toBe(0);
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
assert.isTrue(set.isEmpty);
|
|
19
20
|
});
|
|
20
21
|
|
|
21
22
|
test('should create set from array', () => {
|
|
22
23
|
const set = ISet.create([1, 2, 3, 2, 1]);
|
|
23
24
|
|
|
24
25
|
expect(set.size).toBe(3);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
|
|
27
|
+
assert.isTrue(set.has(1));
|
|
28
|
+
|
|
29
|
+
assert.isTrue(set.has(2));
|
|
30
|
+
|
|
31
|
+
assert.isTrue(set.has(3));
|
|
28
32
|
});
|
|
29
33
|
|
|
30
34
|
test('should create set from JavaScript Set', () => {
|
|
31
35
|
const jsSet = new Set(['a', 'b', 'c']);
|
|
36
|
+
|
|
32
37
|
const set = ISet.create(jsSet);
|
|
33
38
|
|
|
34
39
|
expect(set.size).toBe(3);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
|
|
41
|
+
assert.isTrue(set.has('a'));
|
|
42
|
+
|
|
43
|
+
assert.isTrue(set.has('b'));
|
|
44
|
+
|
|
45
|
+
assert.isTrue(set.has('c'));
|
|
38
46
|
});
|
|
39
47
|
|
|
40
48
|
test('should create set from another ISet', () => {
|
|
41
49
|
const original = ISet.create([1, 2, 3]);
|
|
50
|
+
|
|
42
51
|
const copy = ISet.create(original);
|
|
43
52
|
|
|
44
53
|
expect(copy.size).toBe(3);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
|
|
55
|
+
assert.isTrue(copy.has(1));
|
|
56
|
+
|
|
57
|
+
assert.isTrue(copy.has(2));
|
|
58
|
+
|
|
59
|
+
assert.isTrue(copy.has(3));
|
|
48
60
|
});
|
|
49
61
|
});
|
|
50
62
|
|
|
@@ -68,13 +80,13 @@ describe('isEmpty property', () => {
|
|
|
68
80
|
test('should return true for empty set', () => {
|
|
69
81
|
const set = ISet.create<string>([]);
|
|
70
82
|
|
|
71
|
-
|
|
83
|
+
assert.isTrue(set.isEmpty);
|
|
72
84
|
});
|
|
73
85
|
|
|
74
86
|
test('should return false for non-empty set', () => {
|
|
75
87
|
const set = ISet.create([1, 2, 3]);
|
|
76
88
|
|
|
77
|
-
|
|
89
|
+
assert.isFalse(set.isEmpty);
|
|
78
90
|
});
|
|
79
91
|
});
|
|
80
92
|
|
|
@@ -84,39 +96,41 @@ describe('ISet.has', () => {
|
|
|
84
96
|
|
|
85
97
|
expectType<typeof s0.has, (value: 1 | 2 | 3) => boolean>('<=');
|
|
86
98
|
|
|
87
|
-
|
|
99
|
+
assert.isTrue(s0.has(2));
|
|
88
100
|
});
|
|
89
101
|
|
|
90
102
|
test('case 2', () => {
|
|
91
103
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
92
104
|
|
|
93
|
-
|
|
105
|
+
assert.isFalse(s0.has(4));
|
|
94
106
|
});
|
|
95
107
|
|
|
96
108
|
test('case 3', () => {
|
|
97
109
|
const s0 = ISet.create<number>([]);
|
|
98
110
|
|
|
99
|
-
|
|
111
|
+
assert.isFalse(s0.has(1));
|
|
100
112
|
});
|
|
101
113
|
|
|
102
114
|
test('case 4', () => {
|
|
103
115
|
const s0 = ISet.create([1, 2, 3, Number.NaN] as const);
|
|
104
116
|
|
|
105
|
-
|
|
117
|
+
assert.isTrue(s0.has(Number.NaN));
|
|
106
118
|
});
|
|
107
119
|
|
|
108
120
|
test('should handle boolean values', () => {
|
|
109
121
|
const set = ISet.create([true, false]);
|
|
110
122
|
|
|
111
|
-
|
|
112
|
-
|
|
123
|
+
assert.isTrue(set.has(true));
|
|
124
|
+
|
|
125
|
+
assert.isTrue(set.has(false));
|
|
113
126
|
});
|
|
114
127
|
|
|
115
128
|
test('should handle null and undefined', () => {
|
|
116
129
|
const set = ISet.create([null, undefined]);
|
|
117
130
|
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
assert.isTrue(set.has(null));
|
|
132
|
+
|
|
133
|
+
assert.isTrue(set.has(undefined));
|
|
120
134
|
});
|
|
121
135
|
});
|
|
122
136
|
|
|
@@ -129,48 +143,50 @@ describe('ISet.every', () => {
|
|
|
129
143
|
(predicate: (value: 2 | 4 | 6) => boolean) => boolean
|
|
130
144
|
>('<=');
|
|
131
145
|
|
|
132
|
-
|
|
146
|
+
assert.isTrue(s0.every((x) => x % 2 === 0));
|
|
133
147
|
});
|
|
134
148
|
|
|
135
149
|
test('case 2', () => {
|
|
136
150
|
const s0 = ISet.create([1, 2, 3] as const);
|
|
137
151
|
|
|
138
|
-
|
|
152
|
+
assert.isFalse(s0.every((x) => x % 2 === 0));
|
|
139
153
|
});
|
|
140
154
|
|
|
141
155
|
test('case 3', () => {
|
|
142
156
|
const s0 = ISet.create<number>([]);
|
|
143
157
|
|
|
144
|
-
|
|
158
|
+
assert.isTrue(s0.every((x) => x % 2 === 0));
|
|
145
159
|
});
|
|
146
160
|
|
|
147
161
|
test('should return true when all elements satisfy predicate', () => {
|
|
148
162
|
const set = ISet.create([2, 4, 6, 8]);
|
|
149
163
|
|
|
150
|
-
|
|
164
|
+
assert.isTrue(set.every((x) => x % 2 === 0));
|
|
151
165
|
});
|
|
152
166
|
|
|
153
167
|
test('should return false when some elements do not satisfy predicate', () => {
|
|
154
168
|
const set = ISet.create([1, 2, 3, 4]);
|
|
155
169
|
|
|
156
|
-
|
|
170
|
+
assert.isFalse(set.every((x) => x % 2 === 0));
|
|
157
171
|
});
|
|
158
172
|
|
|
159
173
|
test('should return true for empty set', () => {
|
|
160
174
|
const set = ISet.create<number>([]);
|
|
161
175
|
|
|
162
|
-
|
|
176
|
+
assert.isTrue(set.every((x) => x > 0));
|
|
163
177
|
});
|
|
164
178
|
});
|
|
165
179
|
|
|
166
180
|
describe('every method as type guard', () => {
|
|
167
181
|
test('should narrow type when used as type guard', () => {
|
|
168
182
|
const set = ISet.create<string | number>(['hello', 'world']);
|
|
183
|
+
|
|
169
184
|
if (set.every((value): value is string => typeof value === 'string')) {
|
|
170
185
|
// Type should be narrowed to ISet<string>
|
|
171
186
|
const values = set.toArray();
|
|
187
|
+
|
|
172
188
|
for (const value of values) {
|
|
173
|
-
|
|
189
|
+
assert.isTrue(isString(value));
|
|
174
190
|
}
|
|
175
191
|
}
|
|
176
192
|
});
|
|
@@ -178,9 +194,9 @@ describe('every method as type guard', () => {
|
|
|
178
194
|
test('should work with mixed types that fail guard', () => {
|
|
179
195
|
const set = ISet.create<string | number>(['hello', 42, 'world']);
|
|
180
196
|
|
|
181
|
-
|
|
197
|
+
assert.isFalse(
|
|
182
198
|
set.every((value): value is string => typeof value === 'string'),
|
|
183
|
-
)
|
|
199
|
+
);
|
|
184
200
|
});
|
|
185
201
|
});
|
|
186
202
|
|
|
@@ -193,44 +209,45 @@ describe('ISet.some', () => {
|
|
|
193
209
|
(predicate: (value: 1 | 3 | 5) => boolean) => boolean
|
|
194
210
|
>('<=');
|
|
195
211
|
|
|
196
|
-
|
|
212
|
+
assert.isFalse(s0.some((x) => x % 2 === 0));
|
|
197
213
|
});
|
|
198
214
|
|
|
199
215
|
test('case 2', () => {
|
|
200
216
|
const s0 = ISet.create([1, 2, 3] as const);
|
|
201
217
|
|
|
202
|
-
|
|
218
|
+
assert.isTrue(s0.some((x) => x % 2 === 0));
|
|
203
219
|
});
|
|
204
220
|
|
|
205
221
|
test('case 3', () => {
|
|
206
222
|
const s0 = ISet.create<number>([]);
|
|
207
223
|
|
|
208
|
-
|
|
224
|
+
assert.isFalse(s0.some((x) => x % 2 === 0));
|
|
209
225
|
});
|
|
210
226
|
|
|
211
227
|
test('should return true when at least one element satisfies predicate', () => {
|
|
212
228
|
const set = ISet.create([1, 3, 5, 6]);
|
|
213
229
|
|
|
214
|
-
|
|
230
|
+
assert.isTrue(set.some((x) => x % 2 === 0));
|
|
215
231
|
});
|
|
216
232
|
|
|
217
233
|
test('should return false when no elements satisfy predicate', () => {
|
|
218
234
|
const set = ISet.create([1, 3, 5, 7]);
|
|
219
235
|
|
|
220
|
-
|
|
236
|
+
assert.isFalse(set.some((x) => x % 2 === 0));
|
|
221
237
|
});
|
|
222
238
|
|
|
223
239
|
test('should return false for empty set', () => {
|
|
224
240
|
const set = ISet.create<number>([]);
|
|
225
241
|
|
|
226
|
-
|
|
242
|
+
assert.isFalse(set.some((x) => x > 0));
|
|
227
243
|
});
|
|
228
244
|
|
|
229
245
|
test('should work with complex predicates', () => {
|
|
230
246
|
const set = ISet.create(['hello', 'world', 'test']);
|
|
231
247
|
|
|
232
|
-
|
|
233
|
-
|
|
248
|
+
assert.isTrue(set.some((str) => str.includes('o')));
|
|
249
|
+
|
|
250
|
+
assert.isFalse(set.some((str) => str.includes('z')));
|
|
234
251
|
});
|
|
235
252
|
});
|
|
236
253
|
|
|
@@ -239,9 +256,11 @@ describe('ISet.add', () => {
|
|
|
239
256
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
240
257
|
|
|
241
258
|
expectType<typeof s0.add, (value: number) => ISet<number>>('<=');
|
|
259
|
+
|
|
242
260
|
const s1 = ISet.create<number>([1, 2, 3, 4]);
|
|
243
261
|
|
|
244
262
|
assert.deepStrictEqual(s0.add(4), s1);
|
|
263
|
+
|
|
245
264
|
assert.deepStrictEqual(s0, ISet.create<number>([1, 2, 3]));
|
|
246
265
|
});
|
|
247
266
|
|
|
@@ -249,6 +268,7 @@ describe('ISet.add', () => {
|
|
|
249
268
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
250
269
|
|
|
251
270
|
assert.deepStrictEqual(s0.add(2), ISet.create([1, 2, 3]));
|
|
271
|
+
|
|
252
272
|
assert.deepStrictEqual(s0, ISet.create([1, 2, 3]));
|
|
253
273
|
});
|
|
254
274
|
|
|
@@ -256,21 +276,27 @@ describe('ISet.add', () => {
|
|
|
256
276
|
const s0 = ISet.create<number>([]);
|
|
257
277
|
|
|
258
278
|
assert.deepStrictEqual(s0.add(1), ISet.create([1]));
|
|
279
|
+
|
|
259
280
|
assert.deepStrictEqual(s0, ISet.create<number>([]));
|
|
260
281
|
});
|
|
261
282
|
|
|
262
283
|
test('should add new elements and maintain immutability', () => {
|
|
263
284
|
const original = ISet.create<number>([1, 2, 3]);
|
|
285
|
+
|
|
264
286
|
const modified = original.add(4);
|
|
265
287
|
|
|
266
288
|
expect(original.size).toBe(3);
|
|
289
|
+
|
|
267
290
|
expect(modified.size).toBe(4);
|
|
268
|
-
|
|
269
|
-
|
|
291
|
+
|
|
292
|
+
assert.isFalse(original.has(4));
|
|
293
|
+
|
|
294
|
+
assert.isTrue(modified.has(4));
|
|
270
295
|
});
|
|
271
296
|
|
|
272
297
|
test('should return same instance when adding existing element', () => {
|
|
273
298
|
const set = ISet.create([1, 2, 3]);
|
|
299
|
+
|
|
274
300
|
const result = set.add(2);
|
|
275
301
|
|
|
276
302
|
expect(result).toBe(set);
|
|
@@ -278,13 +304,18 @@ describe('ISet.add', () => {
|
|
|
278
304
|
|
|
279
305
|
test('should handle special values', () => {
|
|
280
306
|
const set = ISet.create<number | null | undefined>([]);
|
|
307
|
+
|
|
281
308
|
const withNull = set.add(null);
|
|
309
|
+
|
|
282
310
|
const withUndefined = withNull.add(undefined);
|
|
311
|
+
|
|
283
312
|
const withNaN = withUndefined.add(Number.NaN);
|
|
284
313
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
314
|
+
assert.isTrue(withNaN.has(null));
|
|
315
|
+
|
|
316
|
+
assert.isTrue(withNaN.has(undefined));
|
|
317
|
+
|
|
318
|
+
assert.isTrue(withNaN.has(Number.NaN));
|
|
288
319
|
});
|
|
289
320
|
});
|
|
290
321
|
|
|
@@ -295,6 +326,7 @@ describe('ISet.delete', () => {
|
|
|
295
326
|
expectType<typeof s0.delete, (value: number) => ISet<number>>('<=');
|
|
296
327
|
|
|
297
328
|
assert.deepStrictEqual(s0.delete(4), ISet.create<number>([1, 2, 3]));
|
|
329
|
+
|
|
298
330
|
assert.deepStrictEqual(s0, ISet.create<number>([1, 2, 3]));
|
|
299
331
|
});
|
|
300
332
|
|
|
@@ -302,6 +334,7 @@ describe('ISet.delete', () => {
|
|
|
302
334
|
const s0 = ISet.create([1, 2, 3]);
|
|
303
335
|
|
|
304
336
|
assert.deepStrictEqual(s0.delete(2), ISet.create<1 | 2 | 3>([1, 3]));
|
|
337
|
+
|
|
305
338
|
assert.deepStrictEqual(s0, ISet.create([1, 2, 3]));
|
|
306
339
|
});
|
|
307
340
|
|
|
@@ -309,21 +342,27 @@ describe('ISet.delete', () => {
|
|
|
309
342
|
const s0 = ISet.create<number>([]);
|
|
310
343
|
|
|
311
344
|
assert.deepStrictEqual(s0.delete(1), ISet.create<number>([]));
|
|
345
|
+
|
|
312
346
|
assert.deepStrictEqual(s0, ISet.create<number>([]));
|
|
313
347
|
});
|
|
314
348
|
|
|
315
349
|
test('should delete existing elements and maintain immutability', () => {
|
|
316
350
|
const original = ISet.create([1, 2, 3, 4]);
|
|
351
|
+
|
|
317
352
|
const modified = original.delete(2);
|
|
318
353
|
|
|
319
354
|
expect(original.size).toBe(4);
|
|
355
|
+
|
|
320
356
|
expect(modified.size).toBe(3);
|
|
321
|
-
|
|
322
|
-
|
|
357
|
+
|
|
358
|
+
assert.isTrue(original.has(2));
|
|
359
|
+
|
|
360
|
+
assert.isFalse(modified.has(2));
|
|
323
361
|
});
|
|
324
362
|
|
|
325
363
|
test('should return same instance when deleting non-existent element', () => {
|
|
326
364
|
const set = ISet.create<number>([1, 2, 3]);
|
|
365
|
+
|
|
327
366
|
const result = set.delete(4);
|
|
328
367
|
|
|
329
368
|
expect(result).toBe(set);
|
|
@@ -356,6 +395,7 @@ describe('ISet.map', () => {
|
|
|
356
395
|
|
|
357
396
|
test('should transform all elements', () => {
|
|
358
397
|
const set = ISet.create([1, 2, 3]);
|
|
398
|
+
|
|
359
399
|
const doubled = set.map((x) => x * 2);
|
|
360
400
|
|
|
361
401
|
assert.deepStrictEqual(
|
|
@@ -366,11 +406,14 @@ describe('ISet.map', () => {
|
|
|
366
406
|
|
|
367
407
|
test('should handle type transformations', () => {
|
|
368
408
|
const set = ISet.create([1, 2, 3]);
|
|
409
|
+
|
|
369
410
|
const strings = set.map((x) => x.toString());
|
|
370
411
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
412
|
+
assert.isTrue(strings.has('1'));
|
|
413
|
+
|
|
414
|
+
assert.isTrue(strings.has('2'));
|
|
415
|
+
|
|
416
|
+
assert.isTrue(strings.has('3'));
|
|
374
417
|
});
|
|
375
418
|
});
|
|
376
419
|
|
|
@@ -402,156 +445,185 @@ describe('ISet.filter', () => {
|
|
|
402
445
|
|
|
403
446
|
test('should filter elements based on predicate', () => {
|
|
404
447
|
const set = ISet.create([1, 2, 3, 4, 5, 6]);
|
|
448
|
+
|
|
405
449
|
const evens = set.filter((x) => x % 2 === 0);
|
|
406
450
|
|
|
407
451
|
expect(evens.size).toBe(3);
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
452
|
+
|
|
453
|
+
assert.isTrue(evens.has(2));
|
|
454
|
+
|
|
455
|
+
assert.isTrue(evens.has(4));
|
|
456
|
+
|
|
457
|
+
assert.isTrue(evens.has(6));
|
|
411
458
|
});
|
|
412
459
|
|
|
413
460
|
test('should work as type guard', () => {
|
|
414
461
|
const set = ISet.create<string | number>(['hello', 42, 'world', 123]);
|
|
462
|
+
|
|
415
463
|
const strings = set.filter(
|
|
416
464
|
(value): value is string => typeof value === 'string',
|
|
417
465
|
);
|
|
418
466
|
|
|
419
467
|
expect(strings.size).toBe(2);
|
|
420
|
-
|
|
421
|
-
|
|
468
|
+
|
|
469
|
+
assert.isTrue(strings.has('hello'));
|
|
470
|
+
|
|
471
|
+
assert.isTrue(strings.has('world'));
|
|
422
472
|
});
|
|
423
473
|
|
|
424
474
|
test('should return empty set when no elements match', () => {
|
|
425
475
|
const set = ISet.create([1, 3, 5]);
|
|
476
|
+
|
|
426
477
|
const evens = set.filter((x) => x % 2 === 0);
|
|
427
478
|
|
|
428
479
|
expect(evens.size).toBe(0);
|
|
429
|
-
|
|
480
|
+
|
|
481
|
+
assert.isTrue(evens.isEmpty);
|
|
430
482
|
});
|
|
431
483
|
});
|
|
432
484
|
|
|
433
485
|
describe('ISet.filterNot', () => {
|
|
434
486
|
test('should filter out elements that satisfy predicate', () => {
|
|
435
487
|
const set = ISet.create([1, 2, 3, 4, 5, 6]);
|
|
488
|
+
|
|
436
489
|
const odds = set.filterNot((x) => x % 2 === 0);
|
|
437
490
|
|
|
438
491
|
expect(odds.size).toBe(3);
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
492
|
+
|
|
493
|
+
assert.isTrue(odds.has(1));
|
|
494
|
+
|
|
495
|
+
assert.isTrue(odds.has(3));
|
|
496
|
+
|
|
497
|
+
assert.isTrue(odds.has(5));
|
|
442
498
|
});
|
|
443
499
|
|
|
444
500
|
test('should return same set when no elements satisfy predicate', () => {
|
|
445
501
|
const set = ISet.create([1, 3, 5]);
|
|
502
|
+
|
|
446
503
|
const nonEvens = set.filterNot((x) => x % 2 === 0);
|
|
447
504
|
|
|
448
505
|
expect(nonEvens.size).toBe(3);
|
|
449
|
-
|
|
506
|
+
|
|
507
|
+
assert.isTrue(ISet.equal(set, nonEvens));
|
|
450
508
|
});
|
|
451
509
|
|
|
452
510
|
test('should return empty set when all elements satisfy predicate', () => {
|
|
453
511
|
const set = ISet.create([2, 4, 6]);
|
|
512
|
+
|
|
454
513
|
const nonEvens = set.filterNot((x) => x % 2 === 0);
|
|
455
514
|
|
|
456
|
-
|
|
515
|
+
assert.isTrue(nonEvens.isEmpty);
|
|
457
516
|
});
|
|
458
517
|
});
|
|
459
518
|
|
|
460
519
|
describe('ISet.isSubsetOf', () => {
|
|
461
520
|
test('case 1', () => {
|
|
462
521
|
const s0 = ISet.create<number>([1, 2]);
|
|
522
|
+
|
|
463
523
|
const s1 = ISet.create<number>([1, 2, 3]);
|
|
464
524
|
|
|
465
525
|
expectType<typeof s0.isSubsetOf, (other: ISet<number>) => boolean>('<=');
|
|
466
526
|
|
|
467
|
-
|
|
527
|
+
assert.isTrue(s0.isSubsetOf(s1));
|
|
468
528
|
});
|
|
469
529
|
|
|
470
530
|
test('case 2', () => {
|
|
471
531
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
532
|
+
|
|
472
533
|
const s1 = ISet.create<number>([1, 2]);
|
|
473
534
|
|
|
474
|
-
|
|
535
|
+
assert.isFalse(s0.isSubsetOf(s1));
|
|
475
536
|
});
|
|
476
537
|
|
|
477
538
|
test('case 3', () => {
|
|
478
539
|
const s0 = ISet.create<number>([]);
|
|
540
|
+
|
|
479
541
|
const s1 = ISet.create<number>([1, 2, 3]);
|
|
480
542
|
|
|
481
|
-
|
|
543
|
+
assert.isTrue(s0.isSubsetOf(s1));
|
|
482
544
|
});
|
|
483
545
|
|
|
484
546
|
test('should return true for subset relationship', () => {
|
|
485
547
|
const subset = ISet.create<number>([1, 2]);
|
|
548
|
+
|
|
486
549
|
const superset = ISet.create<number>([1, 2, 3, 4]);
|
|
487
550
|
|
|
488
|
-
|
|
551
|
+
assert.isTrue(subset.isSubsetOf(superset));
|
|
489
552
|
});
|
|
490
553
|
|
|
491
554
|
test('should return true for equal sets', () => {
|
|
492
555
|
const set1 = ISet.create<number>([1, 2, 3]);
|
|
556
|
+
|
|
493
557
|
const set2 = ISet.create<number>([1, 2, 3]);
|
|
494
558
|
|
|
495
|
-
|
|
559
|
+
assert.isTrue(set1.isSubsetOf(set2));
|
|
496
560
|
});
|
|
497
561
|
|
|
498
562
|
test('should return false for non-subset', () => {
|
|
499
563
|
const set1 = ISet.create<number>([1, 2, 5]);
|
|
564
|
+
|
|
500
565
|
const set2 = ISet.create<number>([1, 2, 3, 4]);
|
|
501
566
|
|
|
502
|
-
|
|
567
|
+
assert.isFalse(set1.isSubsetOf(set2));
|
|
503
568
|
});
|
|
504
569
|
});
|
|
505
570
|
|
|
506
571
|
describe('ISet.isSupersetOf', () => {
|
|
507
572
|
test('case 1', () => {
|
|
508
573
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
574
|
+
|
|
509
575
|
const s1 = ISet.create<number>([1, 2]);
|
|
510
576
|
|
|
511
577
|
expectType<typeof s0.isSupersetOf, (other: ISet<number>) => boolean>('<=');
|
|
512
578
|
|
|
513
|
-
|
|
579
|
+
assert.isTrue(s0.isSupersetOf(s1));
|
|
514
580
|
});
|
|
515
581
|
|
|
516
582
|
test('case 2', () => {
|
|
517
583
|
const s0 = ISet.create<number>([1, 2]);
|
|
584
|
+
|
|
518
585
|
const s1 = ISet.create<number>([1, 2, 3]);
|
|
519
586
|
|
|
520
|
-
|
|
587
|
+
assert.isFalse(s0.isSupersetOf(s1));
|
|
521
588
|
});
|
|
522
589
|
|
|
523
590
|
test('case 3', () => {
|
|
524
591
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
592
|
+
|
|
525
593
|
const s1 = ISet.create<number>([]);
|
|
526
594
|
|
|
527
|
-
|
|
595
|
+
assert.isTrue(s0.isSupersetOf(s1));
|
|
528
596
|
});
|
|
529
597
|
|
|
530
598
|
test('should return true for superset relationship', () => {
|
|
531
599
|
const superset = ISet.create<number>([1, 2, 3, 4]);
|
|
600
|
+
|
|
532
601
|
const subset = ISet.create<number>([1, 2]);
|
|
533
602
|
|
|
534
|
-
|
|
603
|
+
assert.isTrue(superset.isSupersetOf(subset));
|
|
535
604
|
});
|
|
536
605
|
|
|
537
606
|
test('should return true for equal sets', () => {
|
|
538
607
|
const set1 = ISet.create<number>([1, 2, 3]);
|
|
608
|
+
|
|
539
609
|
const set2 = ISet.create<number>([1, 2, 3]);
|
|
540
610
|
|
|
541
|
-
|
|
611
|
+
assert.isTrue(set1.isSupersetOf(set2));
|
|
542
612
|
});
|
|
543
613
|
|
|
544
614
|
test('should return false for non-superset', () => {
|
|
545
615
|
const set1 = ISet.create<number>([1, 2, 3]);
|
|
616
|
+
|
|
546
617
|
const set2 = ISet.create<number>([1, 2, 3, 4]);
|
|
547
618
|
|
|
548
|
-
|
|
619
|
+
assert.isFalse(set1.isSupersetOf(set2));
|
|
549
620
|
});
|
|
550
621
|
});
|
|
551
622
|
|
|
552
623
|
describe('ISet.subtract', () => {
|
|
553
624
|
test('case 1', () => {
|
|
554
625
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
626
|
+
|
|
555
627
|
const s1 = ISet.create<number>([2, 4]);
|
|
556
628
|
|
|
557
629
|
expectType<typeof s0.subtract, (other: ISet<number>) => ISet<number>>('<=');
|
|
@@ -561,6 +633,7 @@ describe('ISet.subtract', () => {
|
|
|
561
633
|
|
|
562
634
|
test('case 2', () => {
|
|
563
635
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
636
|
+
|
|
564
637
|
const s1 = ISet.create<number>([]);
|
|
565
638
|
|
|
566
639
|
assert.deepStrictEqual(s0.subtract(s1), ISet.create<number>([1, 2, 3]));
|
|
@@ -568,6 +641,7 @@ describe('ISet.subtract', () => {
|
|
|
568
641
|
|
|
569
642
|
test('case 3', () => {
|
|
570
643
|
const s0 = ISet.create<number>([]);
|
|
644
|
+
|
|
571
645
|
const s1 = ISet.create<number>([1, 2, 3]);
|
|
572
646
|
|
|
573
647
|
assert.deepStrictEqual(s0.subtract(s1), ISet.create<number>([]));
|
|
@@ -575,26 +649,33 @@ describe('ISet.subtract', () => {
|
|
|
575
649
|
|
|
576
650
|
test('should return elements in first set but not in second', () => {
|
|
577
651
|
const set1 = ISet.create<number>([1, 2, 3, 4, 5]);
|
|
652
|
+
|
|
578
653
|
const set2 = ISet.create<number>([3, 4, 5, 6, 7]);
|
|
654
|
+
|
|
579
655
|
const result = set1.subtract(set2);
|
|
580
656
|
|
|
581
657
|
expect(result.size).toBe(2);
|
|
582
|
-
|
|
583
|
-
|
|
658
|
+
|
|
659
|
+
assert.isTrue(result.has(1));
|
|
660
|
+
|
|
661
|
+
assert.isTrue(result.has(2));
|
|
584
662
|
});
|
|
585
663
|
|
|
586
664
|
test('should return empty set when all elements are removed', () => {
|
|
587
665
|
const set1 = ISet.create<number>([1, 2, 3]);
|
|
666
|
+
|
|
588
667
|
const set2 = ISet.create<number>([1, 2, 3, 4, 5]);
|
|
668
|
+
|
|
589
669
|
const result = set1.subtract(set2);
|
|
590
670
|
|
|
591
|
-
|
|
671
|
+
assert.isTrue(result.isEmpty);
|
|
592
672
|
});
|
|
593
673
|
});
|
|
594
674
|
|
|
595
675
|
describe('ISet.intersection', () => {
|
|
596
676
|
test('case 1', () => {
|
|
597
677
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
678
|
+
|
|
598
679
|
const s1 = ISet.create<number>([2, 3, 4]);
|
|
599
680
|
|
|
600
681
|
expectType<
|
|
@@ -610,6 +691,7 @@ describe('ISet.intersection', () => {
|
|
|
610
691
|
|
|
611
692
|
test('case 2', () => {
|
|
612
693
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
694
|
+
|
|
613
695
|
const s1 = ISet.create<number>([]);
|
|
614
696
|
|
|
615
697
|
assert.deepStrictEqual(ISet.intersection(s0, s1), ISet.create<number>([]));
|
|
@@ -617,6 +699,7 @@ describe('ISet.intersection', () => {
|
|
|
617
699
|
|
|
618
700
|
test('case 3', () => {
|
|
619
701
|
const s0 = ISet.create<number>([]);
|
|
702
|
+
|
|
620
703
|
const s1 = ISet.create<number>([1, 2, 3]);
|
|
621
704
|
|
|
622
705
|
assert.deepStrictEqual(ISet.intersection(s0, s1), ISet.create<number>([]));
|
|
@@ -624,26 +707,33 @@ describe('ISet.intersection', () => {
|
|
|
624
707
|
|
|
625
708
|
test('should return common elements', () => {
|
|
626
709
|
const set1 = ISet.create<number>([1, 2, 3, 4]);
|
|
710
|
+
|
|
627
711
|
const set2 = ISet.create<number>([3, 4, 5, 6]);
|
|
712
|
+
|
|
628
713
|
const result = ISet.intersection(set1, set2);
|
|
629
714
|
|
|
630
715
|
expect(result.size).toBe(2);
|
|
631
|
-
|
|
632
|
-
|
|
716
|
+
|
|
717
|
+
assert.isTrue(result.has(3));
|
|
718
|
+
|
|
719
|
+
assert.isTrue(result.has(4));
|
|
633
720
|
});
|
|
634
721
|
|
|
635
722
|
test('should return empty set when no common elements', () => {
|
|
636
723
|
const set1 = ISet.create<number>([1, 2]);
|
|
724
|
+
|
|
637
725
|
const set2 = ISet.create<number>([3, 4]);
|
|
726
|
+
|
|
638
727
|
const result = ISet.intersection(set1, set2);
|
|
639
728
|
|
|
640
|
-
|
|
729
|
+
assert.isTrue(result.isEmpty);
|
|
641
730
|
});
|
|
642
731
|
});
|
|
643
732
|
|
|
644
733
|
describe('ISet.intersect', () => {
|
|
645
734
|
test('case 1', () => {
|
|
646
735
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
736
|
+
|
|
647
737
|
const s1 = ISet.create<number>([2, 3, 4]);
|
|
648
738
|
|
|
649
739
|
expectType<typeof s0.intersect, (other: ISet<number>) => ISet<number>>(
|
|
@@ -655,6 +745,7 @@ describe('ISet.intersect', () => {
|
|
|
655
745
|
|
|
656
746
|
test('case 2', () => {
|
|
657
747
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
748
|
+
|
|
658
749
|
const s1 = ISet.create<number>([]);
|
|
659
750
|
|
|
660
751
|
assert.deepStrictEqual(s0.intersect(s1), ISet.create<number>([]));
|
|
@@ -662,6 +753,7 @@ describe('ISet.intersect', () => {
|
|
|
662
753
|
|
|
663
754
|
test('case 3', () => {
|
|
664
755
|
const s0 = ISet.create<number>([]);
|
|
756
|
+
|
|
665
757
|
const s1 = ISet.create<number>([1, 2, 3]);
|
|
666
758
|
|
|
667
759
|
assert.deepStrictEqual(s0.intersect(s1), ISet.create<number>([]));
|
|
@@ -669,18 +761,23 @@ describe('ISet.intersect', () => {
|
|
|
669
761
|
|
|
670
762
|
test('should return common elements using instance method', () => {
|
|
671
763
|
const set1 = ISet.create<number>([1, 2, 3, 4]);
|
|
764
|
+
|
|
672
765
|
const set2 = ISet.create<number>([3, 4, 5, 6]);
|
|
766
|
+
|
|
673
767
|
const result = set1.intersect(set2);
|
|
674
768
|
|
|
675
769
|
expect(result.size).toBe(2);
|
|
676
|
-
|
|
677
|
-
|
|
770
|
+
|
|
771
|
+
assert.isTrue(result.has(3));
|
|
772
|
+
|
|
773
|
+
assert.isTrue(result.has(4));
|
|
678
774
|
});
|
|
679
775
|
});
|
|
680
776
|
|
|
681
777
|
describe('ISet.union', () => {
|
|
682
778
|
test('case 1', () => {
|
|
683
779
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
780
|
+
|
|
684
781
|
const s1 = ISet.create<number>([3, 4, 5]);
|
|
685
782
|
|
|
686
783
|
expectType<
|
|
@@ -696,6 +793,7 @@ describe('ISet.union', () => {
|
|
|
696
793
|
|
|
697
794
|
test('case 2', () => {
|
|
698
795
|
const s0 = ISet.create([1, 2, 3]);
|
|
796
|
+
|
|
699
797
|
const s1 = ISet.create<number>([]);
|
|
700
798
|
|
|
701
799
|
assert.deepStrictEqual(ISet.union(s0, s1), ISet.create<number>([1, 2, 3]));
|
|
@@ -703,6 +801,7 @@ describe('ISet.union', () => {
|
|
|
703
801
|
|
|
704
802
|
test('case 3', () => {
|
|
705
803
|
const s0 = ISet.create<number>([]);
|
|
804
|
+
|
|
706
805
|
const s1 = ISet.create<number>([1, 2, 3]);
|
|
707
806
|
|
|
708
807
|
assert.deepStrictEqual(ISet.union(s0, s1), ISet.create<number>([1, 2, 3]));
|
|
@@ -710,20 +809,28 @@ describe('ISet.union', () => {
|
|
|
710
809
|
|
|
711
810
|
test('should return combined elements using static method', () => {
|
|
712
811
|
const set1 = ISet.create<number>([1, 2, 3]);
|
|
812
|
+
|
|
713
813
|
const set2 = ISet.create<number>([3, 4, 5]);
|
|
814
|
+
|
|
714
815
|
const result = ISet.union(set1, set2);
|
|
715
816
|
|
|
716
817
|
expect(result.size).toBe(5);
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
818
|
+
|
|
819
|
+
assert.isTrue(result.has(1));
|
|
820
|
+
|
|
821
|
+
assert.isTrue(result.has(2));
|
|
822
|
+
|
|
823
|
+
assert.isTrue(result.has(3));
|
|
824
|
+
|
|
825
|
+
assert.isTrue(result.has(4));
|
|
826
|
+
|
|
827
|
+
assert.isTrue(result.has(5));
|
|
722
828
|
});
|
|
723
829
|
|
|
724
830
|
describe('instance method', () => {
|
|
725
831
|
test('case 1', () => {
|
|
726
832
|
const s0 = ISet.create([1, 2, 3] as const);
|
|
833
|
+
|
|
727
834
|
const s1 = ISet.create([3, 4, 5] as const);
|
|
728
835
|
|
|
729
836
|
expectType<typeof s0.union, (other: ISet<number>) => ISet<number>>('<=');
|
|
@@ -736,6 +843,7 @@ describe('ISet.union', () => {
|
|
|
736
843
|
|
|
737
844
|
test('case 2', () => {
|
|
738
845
|
const s0 = ISet.create<number>([1, 2, 3]);
|
|
846
|
+
|
|
739
847
|
const s1 = ISet.create<number>([]);
|
|
740
848
|
|
|
741
849
|
assert.deepStrictEqual(s0.union(s1), ISet.create<number>([1, 2, 3]));
|
|
@@ -743,6 +851,7 @@ describe('ISet.union', () => {
|
|
|
743
851
|
|
|
744
852
|
test('case 3', () => {
|
|
745
853
|
const s0 = ISet.create<number>([]);
|
|
854
|
+
|
|
746
855
|
const s1 = ISet.create<number>([1, 2, 3]);
|
|
747
856
|
|
|
748
857
|
assert.deepStrictEqual(s0.union(s1), ISet.create<number>([1, 2, 3]));
|
|
@@ -750,15 +859,22 @@ describe('ISet.union', () => {
|
|
|
750
859
|
|
|
751
860
|
test('should return combined elements using instance method', () => {
|
|
752
861
|
const set1 = ISet.create<number>([1, 2, 3]);
|
|
862
|
+
|
|
753
863
|
const set2 = ISet.create<number>([3, 4, 5]);
|
|
864
|
+
|
|
754
865
|
const result = set1.union(set2);
|
|
755
866
|
|
|
756
867
|
expect(result.size).toBe(5);
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
868
|
+
|
|
869
|
+
assert.isTrue(result.has(1));
|
|
870
|
+
|
|
871
|
+
assert.isTrue(result.has(2));
|
|
872
|
+
|
|
873
|
+
assert.isTrue(result.has(3));
|
|
874
|
+
|
|
875
|
+
assert.isTrue(result.has(4));
|
|
876
|
+
|
|
877
|
+
assert.isTrue(result.has(5));
|
|
762
878
|
});
|
|
763
879
|
});
|
|
764
880
|
});
|
|
@@ -773,6 +889,7 @@ describe('ISet.forEach', () => {
|
|
|
773
889
|
>('<=');
|
|
774
890
|
|
|
775
891
|
const mut_result: (1 | 2 | 3)[] = [];
|
|
892
|
+
|
|
776
893
|
for (const x of s0) {
|
|
777
894
|
mut_result.push(x);
|
|
778
895
|
}
|
|
@@ -785,6 +902,7 @@ describe('ISet.forEach', () => {
|
|
|
785
902
|
|
|
786
903
|
test('should execute callback for each element', () => {
|
|
787
904
|
const set = ISet.create([1, 2, 3]);
|
|
905
|
+
|
|
788
906
|
const mut_collected: number[] = [];
|
|
789
907
|
|
|
790
908
|
for (const value of set) {
|
|
@@ -799,6 +917,7 @@ describe('ISet.forEach', () => {
|
|
|
799
917
|
|
|
800
918
|
test('should not call callback for empty set', () => {
|
|
801
919
|
const set = ISet.create<number>([]);
|
|
920
|
+
|
|
802
921
|
let mut_callCount = 0;
|
|
803
922
|
|
|
804
923
|
// eslint-disable-next-line unicorn/no-array-for-each
|
|
@@ -817,6 +936,7 @@ describe('ISet.keys', () => {
|
|
|
817
936
|
expectType<typeof s0.keys, () => IterableIterator<1 | 2 | 3>>('<=');
|
|
818
937
|
|
|
819
938
|
const mut_result: (1 | 2 | 3)[] = [];
|
|
939
|
+
|
|
820
940
|
for (const x of s0.keys()) {
|
|
821
941
|
mut_result.push(x);
|
|
822
942
|
}
|
|
@@ -835,6 +955,7 @@ describe('ISet.values', () => {
|
|
|
835
955
|
expectType<typeof s0.values, () => IterableIterator<1 | 2 | 3>>('<=');
|
|
836
956
|
|
|
837
957
|
const mut_result: (1 | 2 | 3)[] = [];
|
|
958
|
+
|
|
838
959
|
for (const x of s0.values()) {
|
|
839
960
|
mut_result.push(x);
|
|
840
961
|
}
|
|
@@ -856,6 +977,7 @@ describe('ISet.entries', () => {
|
|
|
856
977
|
>('<=');
|
|
857
978
|
|
|
858
979
|
const mut_result: [1 | 2 | 3, 1 | 2 | 3][] = [];
|
|
980
|
+
|
|
859
981
|
for (const x of s0.entries()) {
|
|
860
982
|
mut_result.push([x[0], x[1]]);
|
|
861
983
|
}
|
|
@@ -891,6 +1013,7 @@ describe('ISet.toArray', () => {
|
|
|
891
1013
|
|
|
892
1014
|
test('should convert set to array', () => {
|
|
893
1015
|
const set = ISet.create([1, 3, 2]);
|
|
1016
|
+
|
|
894
1017
|
const array = set.toArray();
|
|
895
1018
|
|
|
896
1019
|
expect(array).toHaveLength(3);
|
|
@@ -905,16 +1028,21 @@ describe('ISet.toArray', () => {
|
|
|
905
1028
|
describe('ISet.toRawSet', () => {
|
|
906
1029
|
test('should return underlying ReadonlySet', () => {
|
|
907
1030
|
const set = ISet.create([1, 2, 3]);
|
|
1031
|
+
|
|
908
1032
|
const rawSet = set.toRawSet();
|
|
909
1033
|
|
|
910
1034
|
expect(rawSet.size).toBe(3);
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1035
|
+
|
|
1036
|
+
assert.isTrue(rawSet.has(1));
|
|
1037
|
+
|
|
1038
|
+
assert.isTrue(rawSet.has(2));
|
|
1039
|
+
|
|
1040
|
+
assert.isTrue(rawSet.has(3));
|
|
914
1041
|
});
|
|
915
1042
|
|
|
916
1043
|
test('should return empty ReadonlySet for empty ISet', () => {
|
|
917
1044
|
const set = ISet.create<number>([]);
|
|
1045
|
+
|
|
918
1046
|
const rawSet = set.toRawSet();
|
|
919
1047
|
|
|
920
1048
|
expect(rawSet.size).toBe(0);
|
|
@@ -924,92 +1052,110 @@ describe('ISet.toRawSet', () => {
|
|
|
924
1052
|
describe('ISet.equal', () => {
|
|
925
1053
|
test('should return true for equal sets', () => {
|
|
926
1054
|
const set1 = ISet.create([1, 2, 3]);
|
|
1055
|
+
|
|
927
1056
|
const set2 = ISet.create([3, 2, 1]); // Different order
|
|
928
1057
|
|
|
929
|
-
|
|
1058
|
+
assert.isTrue(ISet.equal(set1, set2));
|
|
930
1059
|
});
|
|
931
1060
|
|
|
932
1061
|
test('should return false for sets with different sizes', () => {
|
|
933
1062
|
const set1 = ISet.create<'a' | 'b' | 'c' | 'd'>(['a', 'b']);
|
|
1063
|
+
|
|
934
1064
|
const set2 = ISet.create<'a' | 'b' | 'c' | 'd'>(['a', 'b', 'c']);
|
|
935
1065
|
|
|
936
|
-
|
|
1066
|
+
assert.isFalse(ISet.equal(set1, set2));
|
|
937
1067
|
});
|
|
938
1068
|
|
|
939
1069
|
test('should return false for sets with different elements', () => {
|
|
940
1070
|
const set1 = ISet.create<'a' | 'b' | 'c' | 'd'>(['a', 'b', 'c']);
|
|
1071
|
+
|
|
941
1072
|
const set2 = ISet.create<'a' | 'b' | 'c' | 'd'>(['a', 'b', 'd']);
|
|
942
1073
|
|
|
943
|
-
|
|
1074
|
+
assert.isFalse(ISet.equal(set1, set2));
|
|
944
1075
|
});
|
|
945
1076
|
|
|
946
1077
|
test('should return true for empty sets', () => {
|
|
947
1078
|
const set1 = ISet.create<string>([]);
|
|
1079
|
+
|
|
948
1080
|
const set2 = ISet.create<string>([]);
|
|
949
1081
|
|
|
950
|
-
|
|
1082
|
+
assert.isTrue(ISet.equal(set1, set2));
|
|
951
1083
|
});
|
|
952
1084
|
|
|
953
1085
|
test('should handle sets with special values', () => {
|
|
954
1086
|
const set1 = ISet.create([Number.NaN, null, undefined]);
|
|
1087
|
+
|
|
955
1088
|
const set2 = ISet.create([undefined, Number.NaN, null]);
|
|
956
1089
|
|
|
957
|
-
|
|
1090
|
+
assert.isTrue(ISet.equal(set1, set2));
|
|
958
1091
|
});
|
|
959
1092
|
});
|
|
960
1093
|
|
|
961
1094
|
describe('ISet.diff', () => {
|
|
962
1095
|
test('should compute differences between sets', () => {
|
|
963
1096
|
const oldSet = ISet.create<'a' | 'b' | 'c' | 'd'>(['a', 'b', 'c']);
|
|
1097
|
+
|
|
964
1098
|
const newSet = ISet.create<'a' | 'b' | 'c' | 'd'>(['b', 'c', 'd']);
|
|
965
1099
|
|
|
966
1100
|
const diff = ISet.diff(oldSet, newSet);
|
|
967
1101
|
|
|
968
1102
|
expect(diff.deleted.size).toBe(1);
|
|
969
|
-
|
|
1103
|
+
|
|
1104
|
+
assert.isTrue(diff.deleted.has('a'));
|
|
970
1105
|
|
|
971
1106
|
expect(diff.added.size).toBe(1);
|
|
972
|
-
|
|
1107
|
+
|
|
1108
|
+
assert.isTrue(diff.added.has('d'));
|
|
973
1109
|
});
|
|
974
1110
|
|
|
975
1111
|
test('should handle no changes', () => {
|
|
976
1112
|
const set1 = ISet.create(['a', 'b', 'c']);
|
|
1113
|
+
|
|
977
1114
|
const set2 = ISet.create(['a', 'b', 'c']);
|
|
978
1115
|
|
|
979
1116
|
const diff = ISet.diff(set1, set2);
|
|
980
1117
|
|
|
981
|
-
|
|
982
|
-
|
|
1118
|
+
assert.isTrue(diff.deleted.isEmpty);
|
|
1119
|
+
|
|
1120
|
+
assert.isTrue(diff.added.isEmpty);
|
|
983
1121
|
});
|
|
984
1122
|
|
|
985
1123
|
test('should handle complete replacement', () => {
|
|
986
1124
|
const oldSet = ISet.create<'a' | 'b' | 'c' | 'd'>(['a', 'b']);
|
|
1125
|
+
|
|
987
1126
|
const newSet = ISet.create<'a' | 'b' | 'c' | 'd'>(['c', 'd']);
|
|
988
1127
|
|
|
989
1128
|
const diff = ISet.diff(oldSet, newSet);
|
|
990
1129
|
|
|
991
1130
|
expect(diff.deleted.size).toBe(2);
|
|
992
|
-
|
|
993
|
-
|
|
1131
|
+
|
|
1132
|
+
assert.isTrue(diff.deleted.has('a'));
|
|
1133
|
+
|
|
1134
|
+
assert.isTrue(diff.deleted.has('b'));
|
|
994
1135
|
|
|
995
1136
|
expect(diff.added.size).toBe(2);
|
|
996
|
-
|
|
997
|
-
|
|
1137
|
+
|
|
1138
|
+
assert.isTrue(diff.added.has('c'));
|
|
1139
|
+
|
|
1140
|
+
assert.isTrue(diff.added.has('d'));
|
|
998
1141
|
});
|
|
999
1142
|
|
|
1000
1143
|
test('should handle empty sets', () => {
|
|
1001
1144
|
const emptySet = ISet.create<string>([]);
|
|
1145
|
+
|
|
1002
1146
|
const nonEmptySet = ISet.create<string>(['a', 'b']);
|
|
1003
1147
|
|
|
1004
1148
|
const diff1 = ISet.diff(emptySet, nonEmptySet);
|
|
1005
1149
|
|
|
1006
|
-
|
|
1150
|
+
assert.isTrue(diff1.deleted.isEmpty);
|
|
1151
|
+
|
|
1007
1152
|
expect(diff1.added.size).toBe(2);
|
|
1008
1153
|
|
|
1009
1154
|
const diff2 = ISet.diff(nonEmptySet, emptySet);
|
|
1010
1155
|
|
|
1011
1156
|
expect(diff2.deleted.size).toBe(2);
|
|
1012
|
-
|
|
1157
|
+
|
|
1158
|
+
assert.isTrue(diff2.added.isEmpty);
|
|
1013
1159
|
});
|
|
1014
1160
|
});
|
|
1015
1161
|
|
|
@@ -1024,22 +1170,29 @@ describe('ISet.withMutations', () => {
|
|
|
1024
1170
|
]);
|
|
1025
1171
|
|
|
1026
1172
|
expect(updated.size).toBe(3);
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1173
|
+
|
|
1174
|
+
assert.isTrue(updated.has('b'));
|
|
1175
|
+
|
|
1176
|
+
assert.isTrue(updated.has('c'));
|
|
1177
|
+
|
|
1178
|
+
assert.isTrue(updated.has('d'));
|
|
1179
|
+
|
|
1180
|
+
assert.isFalse(updated.has('a'));
|
|
1031
1181
|
});
|
|
1032
1182
|
|
|
1033
1183
|
test('should handle empty mutations array', () => {
|
|
1034
1184
|
const set = ISet.create(['a', 'b', 'c']);
|
|
1185
|
+
|
|
1035
1186
|
const updated = set.withMutations([]);
|
|
1036
1187
|
|
|
1037
1188
|
expect(updated.size).toBe(set.size);
|
|
1038
|
-
|
|
1189
|
+
|
|
1190
|
+
assert.isTrue(ISet.equal(set, updated));
|
|
1039
1191
|
});
|
|
1040
1192
|
|
|
1041
1193
|
test('should handle duplicate operations', () => {
|
|
1042
1194
|
const set = ISet.create<'a' | 'b'>(['a']);
|
|
1195
|
+
|
|
1043
1196
|
const updated = set.withMutations([
|
|
1044
1197
|
{ type: 'add', key: 'a' }, // Already exists
|
|
1045
1198
|
{ type: 'delete', key: 'b' }, // Doesn't exist
|
|
@@ -1047,14 +1200,17 @@ describe('ISet.withMutations', () => {
|
|
|
1047
1200
|
]);
|
|
1048
1201
|
|
|
1049
1202
|
expect(updated.size).toBe(2);
|
|
1050
|
-
|
|
1051
|
-
|
|
1203
|
+
|
|
1204
|
+
assert.isTrue(updated.has('a'));
|
|
1205
|
+
|
|
1206
|
+
assert.isTrue(updated.has('b'));
|
|
1052
1207
|
});
|
|
1053
1208
|
});
|
|
1054
1209
|
|
|
1055
1210
|
describe('iterable functionality', () => {
|
|
1056
1211
|
test('should work with for-of loops', () => {
|
|
1057
1212
|
const set = ISet.create([1, 2, 3]);
|
|
1213
|
+
|
|
1058
1214
|
const mut_collected: number[] = [];
|
|
1059
1215
|
|
|
1060
1216
|
for (const value of set) {
|
|
@@ -1069,6 +1225,7 @@ describe('iterable functionality', () => {
|
|
|
1069
1225
|
|
|
1070
1226
|
test('should work with spread operator', () => {
|
|
1071
1227
|
const set = ISet.create([1, 2, 3]);
|
|
1228
|
+
|
|
1072
1229
|
const array = Array.from(set);
|
|
1073
1230
|
|
|
1074
1231
|
assert.deepStrictEqual(
|
|
@@ -1079,6 +1236,7 @@ describe('iterable functionality', () => {
|
|
|
1079
1236
|
|
|
1080
1237
|
test('should work with Array.from', () => {
|
|
1081
1238
|
const set = ISet.create([1, 2, 3]);
|
|
1239
|
+
|
|
1082
1240
|
const array = Array.from(set);
|
|
1083
1241
|
|
|
1084
1242
|
assert.deepStrictEqual(
|
|
@@ -1089,6 +1247,7 @@ describe('iterable functionality', () => {
|
|
|
1089
1247
|
|
|
1090
1248
|
test('should work with destructuring', () => {
|
|
1091
1249
|
const set = ISet.create([1, 2]);
|
|
1250
|
+
|
|
1092
1251
|
const values = Array.from(set);
|
|
1093
1252
|
|
|
1094
1253
|
assert.deepStrictEqual(
|
|
@@ -1102,7 +1261,8 @@ describe('edge cases', () => {
|
|
|
1102
1261
|
test('should handle NaN correctly', () => {
|
|
1103
1262
|
const set = ISet.create([Number.NaN, 1, 2]);
|
|
1104
1263
|
|
|
1105
|
-
|
|
1264
|
+
assert.isTrue(set.has(Number.NaN));
|
|
1265
|
+
|
|
1106
1266
|
expect(set.size).toBe(3);
|
|
1107
1267
|
});
|
|
1108
1268
|
|
|
@@ -1110,84 +1270,117 @@ describe('edge cases', () => {
|
|
|
1110
1270
|
const set = ISet.create([true, false, true]);
|
|
1111
1271
|
|
|
1112
1272
|
expect(set.size).toBe(2);
|
|
1113
|
-
|
|
1114
|
-
|
|
1273
|
+
|
|
1274
|
+
assert.isTrue(set.has(true));
|
|
1275
|
+
|
|
1276
|
+
assert.isTrue(set.has(false));
|
|
1115
1277
|
});
|
|
1116
1278
|
|
|
1117
1279
|
test('should handle null and undefined', () => {
|
|
1118
1280
|
const set = ISet.create([null, undefined, null]);
|
|
1119
1281
|
|
|
1120
1282
|
expect(set.size).toBe(2);
|
|
1121
|
-
|
|
1122
|
-
|
|
1283
|
+
|
|
1284
|
+
assert.isTrue(set.has(null));
|
|
1285
|
+
|
|
1286
|
+
assert.isTrue(set.has(undefined));
|
|
1123
1287
|
});
|
|
1124
1288
|
|
|
1125
1289
|
test('should handle symbols by reference', () => {
|
|
1126
1290
|
const sym1 = Symbol('test');
|
|
1291
|
+
|
|
1127
1292
|
const sym2 = Symbol('test'); // Different symbol, same description
|
|
1293
|
+
|
|
1128
1294
|
const set = ISet.create([sym1, sym2]);
|
|
1129
1295
|
|
|
1130
1296
|
expect(set.size).toBe(2);
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1297
|
+
|
|
1298
|
+
assert.isTrue(set.has(sym1));
|
|
1299
|
+
|
|
1300
|
+
assert.isTrue(set.has(sym2));
|
|
1301
|
+
|
|
1302
|
+
assert.isFalse(set.has(Symbol('test'))); // Different symbol
|
|
1134
1303
|
});
|
|
1135
1304
|
});
|
|
1136
1305
|
|
|
1137
1306
|
describe('immutability', () => {
|
|
1138
1307
|
test('should not modify original set when adding', () => {
|
|
1139
1308
|
const original = ISet.create<number>([1, 2, 3]);
|
|
1309
|
+
|
|
1140
1310
|
const modified = original.add(4);
|
|
1141
1311
|
|
|
1142
1312
|
expect(original.size).toBe(3);
|
|
1313
|
+
|
|
1143
1314
|
expect(modified.size).toBe(4);
|
|
1144
|
-
|
|
1145
|
-
|
|
1315
|
+
|
|
1316
|
+
assert.isFalse(original.has(4));
|
|
1317
|
+
|
|
1318
|
+
assert.isTrue(modified.has(4));
|
|
1146
1319
|
});
|
|
1147
1320
|
|
|
1148
1321
|
test('should not modify original set when deleting', () => {
|
|
1149
1322
|
const original = ISet.create([1, 2, 3]);
|
|
1323
|
+
|
|
1150
1324
|
const modified = original.delete(2);
|
|
1151
1325
|
|
|
1152
1326
|
expect(original.size).toBe(3);
|
|
1327
|
+
|
|
1153
1328
|
expect(modified.size).toBe(2);
|
|
1154
|
-
|
|
1155
|
-
|
|
1329
|
+
|
|
1330
|
+
assert.isTrue(original.has(2));
|
|
1331
|
+
|
|
1332
|
+
assert.isFalse(modified.has(2));
|
|
1156
1333
|
});
|
|
1157
1334
|
|
|
1158
1335
|
test('should not modify original set when filtering', () => {
|
|
1159
1336
|
const original = ISet.create([1, 2, 3, 4, 5]);
|
|
1337
|
+
|
|
1160
1338
|
const filtered = original.filter((x) => x % 2 === 0);
|
|
1161
1339
|
|
|
1162
1340
|
expect(original.size).toBe(5);
|
|
1341
|
+
|
|
1163
1342
|
expect(filtered.size).toBe(2);
|
|
1164
|
-
|
|
1165
|
-
|
|
1343
|
+
|
|
1344
|
+
assert.isTrue(original.has(1));
|
|
1345
|
+
|
|
1346
|
+
assert.isFalse(filtered.has(1));
|
|
1166
1347
|
});
|
|
1167
1348
|
|
|
1168
1349
|
test('should not modify original set when mapping', () => {
|
|
1169
1350
|
const original = ISet.create([1, 2, 3]);
|
|
1351
|
+
|
|
1170
1352
|
const mapped = original.map((x) => x * 2);
|
|
1171
1353
|
|
|
1172
1354
|
expect(original.size).toBe(3);
|
|
1355
|
+
|
|
1173
1356
|
expect(mapped.size).toBe(3);
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1357
|
+
|
|
1358
|
+
assert.isTrue(original.has(1));
|
|
1359
|
+
|
|
1360
|
+
assert.isFalse(mapped.has(1));
|
|
1361
|
+
|
|
1362
|
+
assert.isTrue(mapped.has(2));
|
|
1177
1363
|
});
|
|
1178
1364
|
|
|
1179
1365
|
test('should not modify original sets during set operations', () => {
|
|
1180
1366
|
const set1 = ISet.create<number>([1, 2, 3]);
|
|
1367
|
+
|
|
1181
1368
|
const set2 = ISet.create<number>([3, 4, 5]);
|
|
1182
1369
|
|
|
1183
1370
|
const union = set1.union(set2);
|
|
1371
|
+
|
|
1184
1372
|
const intersection = set1.intersect(set2);
|
|
1373
|
+
|
|
1185
1374
|
const difference = set1.subtract(set2);
|
|
1186
1375
|
|
|
1187
1376
|
expect(set1.size).toBe(3);
|
|
1377
|
+
|
|
1188
1378
|
expect(set2.size).toBe(3);
|
|
1379
|
+
|
|
1189
1380
|
expect(union.size).toBe(5);
|
|
1381
|
+
|
|
1190
1382
|
expect(intersection.size).toBe(1);
|
|
1383
|
+
|
|
1191
1384
|
expect(difference.size).toBe(2);
|
|
1192
1385
|
});
|
|
1193
1386
|
});
|