ts-data-forge 14.6.1 → 14.6.3
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/dist/array/impl/array-utils-creation.mjs +126 -26
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +63 -30
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.mjs +68 -52
- package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +109 -73
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +70 -32
- package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +102 -73
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +77 -33
- package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs +75 -122
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +99 -149
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +112 -136
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +146 -38
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +10 -8
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs +13 -50
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +92 -76
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +291 -199
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +53 -55
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/array/impl/index.mjs +17 -17
- package/dist/array/impl/index.mjs.map +1 -1
- package/dist/array/index.mjs +2 -3
- package/dist/array/index.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs +335 -292
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.mjs +280 -239
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/index.mjs +7 -7
- package/dist/collections/index.mjs.map +1 -1
- package/dist/collections/iset-mapped.mjs +448 -265
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.mjs +328 -201
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.mjs +181 -149
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.mjs +167 -138
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +4 -77
- package/dist/entry-point.mjs.map +1 -1
- package/dist/expect-type.mjs +69 -3
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/async-result/async-result.mjs +2 -3
- package/dist/functional/async-result/async-result.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-flat-map.mjs +18 -20
- package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-from-promise.mjs +9 -10
- package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs +12 -14
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-map-err.mjs +15 -18
- package/dist/functional/async-result/impl/async-result-map-err.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-map.mjs +15 -18
- package/dist/functional/async-result/impl/async-result-map.mjs.map +1 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +35 -8
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +1 -1
- package/dist/functional/async-result/impl/index.mjs +8 -7
- package/dist/functional/async-result/impl/index.mjs.map +1 -1
- package/dist/functional/async-result/impl/types.mjs +2 -2
- package/dist/functional/async-result/impl/types.mjs.map +1 -1
- package/dist/functional/async-result/index.mjs +2 -3
- package/dist/functional/async-result/index.mjs.map +1 -1
- package/dist/functional/index.mjs +7 -11
- package/dist/functional/index.mjs.map +1 -1
- package/dist/functional/match.mjs +27 -13
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional/impl/index.mjs +19 -18
- package/dist/functional/optional/impl/index.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs +15 -17
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-filter.mjs +16 -18
- package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs +12 -14
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +24 -3
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +19 -3
- package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +24 -6
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +20 -3
- package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-map.mjs +15 -17
- package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-match.mjs +15 -17
- package/dist/functional/optional/impl/optional-match.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +16 -3
- package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.mjs +12 -14
- package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +22 -6
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +26 -3
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs +11 -13
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +33 -8
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs +6 -9
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +34 -3
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/optional/impl/tag.mjs +3 -4
- package/dist/functional/optional/impl/tag.mjs.map +1 -1
- package/dist/functional/optional/impl/types.mjs +2 -2
- package/dist/functional/optional/impl/types.mjs.map +1 -1
- package/dist/functional/optional/index.mjs +2 -3
- package/dist/functional/optional/index.mjs.map +1 -1
- package/dist/functional/optional/optional.mjs +2 -3
- package/dist/functional/optional/optional.mjs.map +1 -1
- package/dist/functional/pipe.mjs +42 -14
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result/impl/index.mjs +28 -27
- package/dist/functional/result/impl/index.mjs.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +28 -6
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs +16 -17
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.mjs +17 -20
- package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-fold.mjs +17 -20
- package/dist/functional/result/impl/result-fold.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-optional.mjs +16 -19
- package/dist/functional/result/impl/result-from-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +35 -6
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +40 -13
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +19 -3
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +19 -3
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +23 -5
- package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
- package/dist/functional/result/impl/result-map-err.mjs +17 -20
- package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-map.mjs +17 -20
- package/dist/functional/result/impl/result-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-match.mjs +16 -20
- package/dist/functional/result/impl/result-match.mjs.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +28 -6
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-or-else.mjs +13 -14
- package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
- package/dist/functional/result/impl/result-safe-try.mjs +32 -21
- package/dist/functional/result/impl/result-safe-try.mjs.map +1 -1
- package/dist/functional/result/impl/result-safe-unwrap.mjs +39 -11
- package/dist/functional/result/impl/result-safe-unwrap.mjs.map +1 -1
- package/dist/functional/result/impl/result-swap.mjs +21 -6
- package/dist/functional/result/impl/result-swap.mjs.map +1 -1
- package/dist/functional/result/impl/result-to-optional.mjs +28 -5
- package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs +12 -13
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +42 -19
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +31 -6
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs +12 -13
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs +6 -9
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +37 -10
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-zip.mjs +33 -3
- package/dist/functional/result/impl/result-zip.mjs.map +1 -1
- package/dist/functional/result/impl/tag.mjs +3 -4
- package/dist/functional/result/impl/tag.mjs.map +1 -1
- package/dist/functional/result/impl/types.mjs +2 -2
- package/dist/functional/result/impl/types.mjs.map +1 -1
- package/dist/functional/result/index.mjs +2 -3
- package/dist/functional/result/index.mjs.map +1 -1
- package/dist/functional/result/result.mjs +2 -3
- package/dist/functional/result/result.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/index.mjs +29 -28
- package/dist/functional/ternary-result/impl/index.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/tag.mjs +5 -5
- package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +16 -6
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +15 -18
- 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.mjs +29 -33
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +24 -26
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +19 -6
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +27 -12
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +17 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +19 -3
- 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.mjs +26 -6
- 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.mjs +18 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +17 -18
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +20 -23
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +24 -26
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +17 -6
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +11 -14
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +22 -8
- 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.mjs +11 -14
- 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.mjs +29 -18
- 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.mjs +18 -6
- 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.mjs +11 -14
- 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.mjs +6 -8
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +31 -23
- 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.mjs +11 -14
- 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.mjs +26 -16
- 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.mjs +18 -6
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +20 -7
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +46 -18
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/types.mjs +2 -2
- package/dist/functional/ternary-result/impl/types.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/variant-name.mjs +11 -13
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
- package/dist/functional/ternary-result/index.mjs +2 -3
- package/dist/functional/ternary-result/index.mjs.map +1 -1
- package/dist/functional/ternary-result/ternary-result.mjs +2 -3
- package/dist/functional/ternary-result/ternary-result.mjs.map +1 -1
- package/dist/guard/has-key.mjs +42 -3
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/index.mjs +8 -8
- package/dist/guard/index.mjs.map +1 -1
- package/dist/guard/is-non-empty-string.mjs +38 -3
- package/dist/guard/is-non-empty-string.mjs.map +1 -1
- package/dist/guard/is-non-null-object.mjs +35 -3
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-primitive.mjs +46 -15
- package/dist/guard/is-primitive.mjs.map +1 -1
- package/dist/guard/is-record.mjs +87 -4
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.mjs +404 -19
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.mjs +41 -3
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +12 -65
- package/dist/index.mjs.map +1 -1
- package/dist/iterator/index.mjs +2 -2
- package/dist/iterator/index.mjs.map +1 -1
- package/dist/iterator/range.mjs +18 -56
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/index.mjs +2 -2
- package/dist/json/index.mjs.map +1 -1
- package/dist/json/json.mjs +346 -105
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +148 -137
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/index.mjs +33 -33
- package/dist/number/branded-types/index.mjs.map +1 -1
- package/dist/number/branded-types/int.mjs +245 -209
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.mjs +141 -131
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.mjs +141 -131
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.mjs +155 -149
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.mjs +125 -110
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.mjs +126 -115
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +164 -154
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +137 -125
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +137 -125
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +143 -139
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.mjs +116 -99
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.mjs +118 -107
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +144 -129
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +102 -82
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +118 -105
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +118 -105
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +121 -107
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +118 -104
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +118 -104
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +167 -160
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +260 -224
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +134 -122
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +134 -122
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +291 -257
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +134 -122
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +134 -122
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +283 -254
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +134 -123
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.mjs +248 -211
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.mjs +132 -121
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.mjs +132 -121
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/index.mjs +3 -3
- package/dist/number/enum/index.mjs.map +1 -1
- package/dist/number/enum/int8.mjs +146 -131
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.mjs +133 -119
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/index.mjs +6 -37
- package/dist/number/index.mjs.map +1 -1
- package/dist/number/num-arithmetic-types.mjs +42 -1
- package/dist/number/num-arithmetic-types.mjs.map +1 -1
- package/dist/number/num.mjs +549 -91
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.mjs +294 -133
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/index.mjs +2 -2
- package/dist/object/index.mjs.map +1 -1
- package/dist/object/object.mjs +356 -203
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/cast-mutable.mjs +38 -11
- package/dist/others/cast-mutable.mjs.map +1 -1
- package/dist/others/cast-readonly.mjs +37 -11
- package/dist/others/cast-readonly.mjs.map +1 -1
- package/dist/others/debounce-function.mjs +22 -11
- package/dist/others/debounce-function.mjs.map +1 -1
- package/dist/others/fast-deep-equal.mjs +70 -51
- package/dist/others/fast-deep-equal.mjs.map +1 -1
- package/dist/others/if-then.mjs +31 -4
- package/dist/others/if-then.mjs.map +1 -1
- package/dist/others/index.mjs +10 -10
- package/dist/others/index.mjs.map +1 -1
- package/dist/others/map-nullable.mjs +11 -13
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/memoize-function.mjs +14 -16
- package/dist/others/memoize-function.mjs.map +1 -1
- package/dist/others/tuple.mjs +51 -3
- package/dist/others/tuple.mjs.map +1 -1
- package/dist/others/unknown-to-string.mjs +91 -47
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/index.mjs +2 -2
- package/dist/promise/index.mjs.map +1 -1
- package/dist/promise/promise.mjs +49 -8
- package/dist/promise/promise.mjs.map +1 -1
- package/dist/string/index.mjs +2 -2
- package/dist/string/index.mjs.map +1 -1
- package/dist/string/str.mjs +250 -83
- package/dist/string/str.mjs.map +1 -1
- package/dist/types.mjs +2 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +6 -7
- package/src/guard/is-type.test.mts +2 -2
- package/src/number/branded-types/finite-number.test.mts +1 -1
- package/src/number/branded-types/int.test.mts +1 -1
- package/src/number/branded-types/int16.test.mts +1 -1
- package/src/number/branded-types/int32.test.mts +1 -1
- package/src/number/branded-types/non-negative-finite-number.test.mts +1 -1
- package/src/number/branded-types/non-negative-int16.test.mts +1 -1
- package/src/number/branded-types/non-negative-int32.test.mts +1 -1
- package/src/number/branded-types/non-zero-finite-number.test.mts +1 -1
- package/src/number/branded-types/non-zero-int.test.mts +1 -1
- package/src/number/branded-types/non-zero-int16.test.mts +1 -1
- package/src/number/branded-types/non-zero-int32.test.mts +1 -1
- package/src/number/branded-types/non-zero-safe-int.test.mts +1 -1
- package/src/number/branded-types/non-zero-uint16.test.mts +1 -1
- package/src/number/branded-types/non-zero-uint32.test.mts +1 -1
- package/src/number/branded-types/positive-finite-number.test.mts +1 -1
- package/src/number/branded-types/positive-int.test.mts +1 -1
- package/src/number/branded-types/positive-int16.test.mts +1 -1
- package/src/number/branded-types/positive-int32.test.mts +1 -1
- package/src/number/branded-types/positive-safe-int.test.mts +1 -1
- package/src/number/branded-types/positive-uint16.test.mts +1 -1
- package/src/number/branded-types/positive-uint32.test.mts +1 -1
- package/src/number/branded-types/safe-int.test.mts +1 -1
- package/src/number/branded-types/safe-uint.test.mts +1 -1
- package/src/number/branded-types/uint.test.mts +1 -1
- package/src/number/branded-types/uint16.test.mts +1 -1
- package/src/number/branded-types/uint32.test.mts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iset.mjs","sources":["../../src/collections/iset.mts"],"sourcesContent":["/* eslint-disable unicorn/prefer-iterator-to-array-at-end */\nimport {\n type FixedLengthTuple,\n type ReadonlyRecord,\n type WidenLiteral,\n} from 'ts-type-forge';\nimport { asUint32 } from '../number/index.mjs';\nimport { unknownToString } from '../others/index.mjs';\nimport { type MapSetKeyType, type SizeType } from '../types.mjs';\n\n/**\n * Interface for an immutable set with membership testing and set operation\n * support.\n *\n * This interface defines all methods and properties available on ISet\n * instances. All operations that modify the set return new ISet instances,\n * preserving immutability. The underlying implementation uses JavaScript's\n * native Set but creates copies on mutations to maintain immutability.\n *\n * **Immutability Guarantees:**\n *\n * - All mutation operations (add, delete) return new ISet instances\n * - Original ISet instances are never modified\n * - Safe for concurrent access and functional programming patterns\n *\n * **Performance Characteristics:**\n *\n * - has: O(1) average case\n * - add/delete: O(n) due to copying for immutability\n * - set operations (union, intersection, difference): O(n)\n * - map/filter operations: O(n)\n * - iteration: O(n)\n *\n * @template K The type of the elements in the set. Must extend MapSetKeyType\n * (string, number, boolean, etc.)\n */\ntype ISetInterface<K extends MapSetKeyType> = Readonly<{\n // Getting information\n\n /**\n * The number of elements in the set.\n *\n * @example\n *\n * ```ts\n * const set = ISet.create([1, 2, 3]);\n *\n * assert.isTrue(set.size === 3);\n * ```\n */\n size: SizeType.Arr;\n\n /**\n * Checks if the set is empty.\n *\n * @example\n *\n * ```ts\n * const emptySet = ISet.create<number>([]);\n *\n * const filledSet = ISet.create([1, 2]);\n *\n * assert.isTrue(emptySet.isEmpty);\n *\n * assert.isFalse(filledSet.isEmpty);\n * ```\n */\n isEmpty: boolean;\n\n /**\n * Checks if an element exists in the set. Allows for wider literal types for\n * keys during checking.\n *\n * @example\n *\n * ```ts\n * const set = ISet.create(['apple', 'banana']);\n *\n * assert.isTrue(set.has('apple'));\n *\n * assert.isFalse(set.has('cherry'));\n * ```\n *\n * @param key The element to check.\n * @returns `true` if the element exists, `false` otherwise.\n */\n has: (key: K | (WidenLiteral<K> & {})) => boolean;\n\n // Reducing a value\n\n /**\n * Checks if all elements in the set satisfy a predicate. Also supports a\n * type predicate overload that narrows the type of elements in the set if\n * the predicate returns true for all elements.\n *\n * @example\n *\n * ```ts\n * const numbers = ISet.create([2, 4, 6]);\n *\n * const allEven = numbers.every((value) => value % 2 === 0);\n *\n * const narrowed = numbers.every(\n * (value): value is 2 | 4 | 6 => value % 2 === 0,\n * );\n *\n * assert.isTrue(allEven);\n *\n * assert.isTrue(narrowed);\n * ```\n *\n * @template L The narrowed type of the elements.\n * @param predicate A function to test each element.\n * @returns `true` if all elements satisfy the predicate, `false` otherwise.\n */\n every: ((predicate: (key: K) => boolean) => boolean) &\n (<L extends K>(predicate: (key: K) => key is L) => this is ISet<L>);\n\n /**\n * Checks if at least one element in the set satisfies a predicate.\n *\n * @example\n *\n * ```ts\n * const numbers = ISet.create([1, 3, 5]);\n *\n * assert.isTrue(numbers.some((value) => value > 4));\n *\n * assert.isFalse(numbers.some((value) => value > 10));\n * ```\n *\n * @param predicate A function to test each element.\n * @returns `true` if at least one element satisfies the predicate, `false`\n * otherwise.\n */\n some: (predicate: (key: K) => boolean) => boolean;\n\n // Mutation\n\n /**\n * Adds an element to the set.\n *\n * @example\n *\n * ```ts\n * const base = ISet.create<number>([1, 2]);\n *\n * const withThree = base.add(3);\n *\n * const unchanged = base.add(2);\n *\n * assert.deepStrictEqual(Array.from(withThree), [1, 2, 3]);\n *\n * assert.isTrue(unchanged === base);\n * ```\n *\n * @param key The element to add.\n * @returns A new ISet instance with the element added.\n */\n add: (key: K) => ISet<K>;\n\n /**\n * Deletes an element from the set.\n *\n * @example\n *\n * ```ts\n * const base = ISet.create<number>([1, 2, 3]);\n *\n * const withoutTwo = base.delete(2);\n *\n * const unchanged = base.delete(4);\n *\n * assert.deepStrictEqual(Array.from(withoutTwo), [1, 3]);\n *\n * assert.isTrue(unchanged === base);\n * ```\n *\n * @param key The element to delete.\n * @returns A new ISet instance without the specified element.\n */\n delete: (key: K) => ISet<K>;\n\n /**\n * Applies a series of mutations to the set.\n *\n * @example\n *\n * ```ts\n * const base = ISet.create<string>(['a', 'b']);\n *\n * const actions: readonly Readonly<\n * { type: 'add'; key: string } | { type: 'delete'; key: string }\n * >[] = [\n * { type: 'add', key: 'c' },\n * { type: 'delete', key: 'a' },\n * ] as const;\n *\n * const mutated = base.withMutations(actions);\n *\n * assert.deepStrictEqual(Array.from(mutated), ['b', 'c']);\n *\n * assert.deepStrictEqual(Array.from(base), ['a', 'b']);\n * ```\n *\n * @param actions An array of mutation actions (add or delete).\n * @returns A new ISet instance with all mutations applied.\n */\n withMutations: (\n actions: readonly Readonly<\n { type: 'add'; key: K } | { type: 'delete'; key: K }\n >[],\n ) => ISet<K>;\n\n // Sequence algorithms\n\n /**\n * Maps the elements of the set to new elements.\n *\n * @example\n *\n * ```ts\n * const letters = ISet.create(['a', 'b']);\n *\n * const upper = letters.map((value) => value.toUpperCase());\n *\n * assert.deepStrictEqual(Array.from(upper), ['A', 'B']);\n * ```\n *\n * @template K2 The type of the new elements.\n * @param mapFn A function that maps an element to a new element.\n * @returns A new ISet instance with mapped elements.\n */\n map: <K2 extends MapSetKeyType>(mapFn: (key: K) => K2) => ISet<K2>;\n\n /**\n * Filters the elements of the set based on a predicate. Also supports a type\n * predicate overload that narrows the type of elements in the resulting set.\n *\n * @example\n *\n * ```ts\n * const letters = ISet.create(['apple', 'bee', 'cat']);\n *\n * const shortWords = letters.filter((value) => value.length <= 3);\n *\n * const narrowed = letters.filter(\n * (value): value is 'bee' | 'cat' => value.length === 3,\n * );\n *\n * assert.deepStrictEqual(Array.from(shortWords), ['bee', 'cat']);\n *\n * assert.deepStrictEqual(Array.from(narrowed), ['bee', 'cat']);\n * ```\n *\n * @template K2 The narrowed type of the elements.\n * @param predicate A function to test each element.\n * @returns A new ISet instance with elements that satisfy the predicate.\n */\n filter: (<K2 extends K>(predicate: (key: K) => key is K2) => ISet<K2>) &\n ((predicate: (key: K) => boolean) => ISet<K>);\n\n /**\n * Filters the elements of the set by excluding elements for which the\n * predicate returns true.\n *\n * @example\n *\n * ```ts\n * const numbers = ISet.create([1, 2, 3, 4]);\n *\n * const withoutEven = numbers.filterNot((value) => value % 2 === 0);\n *\n * assert.deepStrictEqual(Array.from(withoutEven), [1, 3]);\n * ```\n *\n * @param predicate A function to test each element.\n * @returns A new ISet instance with elements for which the predicate returned\n * `false`.\n */\n filterNot: (predicate: (key: K) => boolean) => ISet<K>;\n\n // Set operations\n\n /**\n * Checks if this set is a subset of another set.\n *\n * @example\n *\n * ```ts\n * const subset = ISet.create<number>([1, 2]);\n *\n * const superset = ISet.create<number>([1, 2, 3]);\n *\n * assert.isTrue(subset.isSubsetOf(superset));\n *\n * assert.isFalse(superset.isSubsetOf(subset));\n * ```\n *\n * @param set The other set.\n * @returns `true` if this set is a subset of the other set, `false`\n * otherwise.\n */\n isSubsetOf: (set: ISet<WidenLiteral<K>>) => boolean;\n\n /**\n * Checks if this set is a superset of another set.\n *\n * @example\n *\n * ```ts\n * const superset = ISet.create<string>(['a', 'b', 'c']);\n *\n * const subset = ISet.create<string>(['a', 'c']);\n *\n * assert.isTrue(superset.isSupersetOf(subset));\n *\n * assert.isFalse(subset.isSupersetOf(superset));\n * ```\n *\n * @param set The other set.\n * @returns `true` if this set is a superset of the other set, `false`\n * otherwise.\n */\n isSupersetOf: (set: ISet<WidenLiteral<K>>) => boolean;\n\n /**\n * Returns a new set with elements that are in this set but not in another\n * set.\n *\n * @example\n *\n * ```ts\n * const all = ISet.create<number>([1, 2, 3, 4]);\n *\n * const toRemove = ISet.create<number>([2, 4]);\n *\n * const difference = all.subtract(toRemove);\n *\n * assert.deepStrictEqual(Array.from(difference), [1, 3]);\n * ```\n *\n * @param set The other set.\n * @returns A new ISet instance representing the set difference.\n */\n subtract: (set: ISet<K>) => ISet<K>;\n\n /**\n * Returns a new set with elements that are common to both this set and\n * another set.\n *\n * @example\n *\n * ```ts\n * const left = ISet.create<string>(['x', 'y']);\n *\n * const right = ISet.create<string>(['y', 'z']);\n *\n * const shared = left.intersect(right);\n *\n * assert.deepStrictEqual(Array.from(shared), ['y']);\n * ```\n *\n * @param set The other set.\n * @returns A new ISet instance representing the set intersection.\n */\n intersect: (set: ISet<K>) => ISet<K>;\n\n /**\n * Returns a new set with all elements from both this set and another set.\n *\n * @example\n *\n * ```ts\n * const numbers = ISet.create([1, 2]);\n *\n * const letters = ISet.create(['a', 'b']);\n *\n * const combined = numbers.union(letters);\n *\n * assert.deepStrictEqual(Array.from(combined), [1, 2, 'a', 'b']);\n * ```\n *\n * @template K2 The type of elements in the other set.\n * @param set The other set.\n * @returns A new ISet instance representing the set union.\n */\n union: <K2 extends MapSetKeyType>(set: ISet<K2>) => ISet<K | K2>;\n\n // Side effects\n\n /**\n * Executes a callback function for each element in the set.\n *\n * @example\n *\n * ```ts\n * const set = ISet.create(['alpha', 'beta']);\n *\n * const mut_collected: string[] = [];\n *\n * set.forEach((value) => {\n * mut_collected.push(value);\n * });\n *\n * assert.deepStrictEqual(mut_collected, ['alpha', 'beta']);\n * ```\n *\n * @param callbackfn A function to execute for each element.\n */\n forEach: (callbackfn: (key: K) => void) => void;\n\n // Iterators\n\n /**\n * Returns an iterator for the elements in the set (alias for values).\n *\n * @example\n *\n * ```ts\n * const set = ISet.create([1, 2]);\n *\n * const keys = Array.from(set.keys());\n *\n * assert.deepStrictEqual(keys, [1, 2]);\n * ```\n *\n * @returns An iterable iterator of elements.\n */\n keys: () => IterableIterator<K>;\n\n /**\n * Returns an iterator for the elements in the set.\n *\n * @example\n *\n * ```ts\n * const set = ISet.create(['x', 'y']);\n *\n * const values = Array.from(set.values());\n *\n * assert.deepStrictEqual(values, ['x', 'y']);\n * ```\n *\n * @returns An iterable iterator of elements.\n */\n values: () => IterableIterator<K>;\n\n /**\n * Returns an iterator for the entries (element-element pairs) in the set.\n *\n * @example\n *\n * ```ts\n * const set = ISet.create(['red', 'blue']);\n *\n * const entries = Array.from(set.entries());\n *\n * assert.deepStrictEqual(entries, [\n * ['red', 'red'],\n * ['blue', 'blue'],\n * ]);\n * ```\n *\n * @returns An iterable iterator of entries.\n */\n entries: () => IterableIterator<FixedLengthTuple<2, K>>;\n\n // Conversion\n\n /**\n * Converts the elements of the set to an array.\n *\n * @example\n *\n * ```ts\n * const set = ISet.create(['north', 'south']);\n *\n * assert.deepStrictEqual(set.toArray(), ['north', 'south']);\n * ```\n *\n * @returns A readonly array of elements.\n */\n toArray: () => readonly K[];\n\n /**\n * Returns the underlying readonly JavaScript Set.\n *\n * @example\n *\n * ```ts\n * const set = ISet.create(['alpha']);\n *\n * const raw = set.toRawSet();\n *\n * assert.isTrue(isSet(raw));\n *\n * assert.isTrue(raw.has('alpha'));\n * ```\n *\n * @returns The raw ReadonlySet instance.\n */\n toRawSet: () => ReadonlySet<K>;\n}>;\n\n/**\n * Represents an immutable set with high-performance operations and\n * comprehensive set algebra support.\n *\n * ISet is a persistent data structure that provides all the functionality of\n * JavaScript's Set while maintaining immutability. All operations that would\n * normally mutate the set instead return new ISet instances, making it safe for\n * functional programming and concurrent access.\n *\n * **Key Features:**\n *\n * - **Immutable**: All mutation operations return new instances\n * - **Set Operations**: Full support for union, intersection, difference,\n * subset/superset checks\n * - **Type Safe**: Full TypeScript support with generic element types\n * - **Iterable**: Implements standard JavaScript iteration protocols\n * - **Functional**: Rich API for map, filter, and functional composition\n *\n * **When to Use:**\n *\n * - Managing collections of unique values with immutability guarantees\n * - Set algebra operations (unions, intersections, differences)\n * - Membership testing with O(1) performance\n * - Functional programming patterns requiring immutable collections\n *\n * @template K The type of the elements in the set. Must extend MapSetKeyType.\n */\nexport type ISet<K extends MapSetKeyType> = Iterable<K> & ISetInterface<K>;\n\n/** Provides utility functions for ISet. */\nexport namespace ISet {\n /**\n * Creates a new ISet instance from an iterable of elements.\n *\n * This factory function accepts any iterable of elements, including arrays,\n * JavaScript Sets, other ISets, or custom iterables. Duplicate elements in\n * the input iterable will be automatically deduplicated in the resulting\n * set.\n *\n * **Performance:** O(n) where n is the number of elements in the iterable.\n *\n * @example\n *\n * ```ts\n * const set = ISet.create(['a', 'a', 'b']);\n *\n * assert.deepStrictEqual(Array.from(set), ['a', 'b']);\n * ```\n *\n * @template K The type of the elements. Must extend MapSetKeyType.\n * @param iterable An iterable of elements (e.g., Array, Set, ISet, etc.)\n * @returns A new ISet instance containing all unique elements from the\n * iterable.\n */\n export const create = <K extends MapSetKeyType>(\n iterable: Iterable<K>,\n ): ISet<K> => new ISetClass<K>(iterable);\n\n /**\n * Checks if two ISet instances are structurally equal.\n *\n * Two ISets are considered equal if they have the same size and contain\n * exactly the same elements. The order of elements does not matter for\n * equality comparison since sets are unordered collections. Elements are\n * compared using JavaScript's `===` operator.\n *\n * **Performance:** O(n) where n is the size of the smaller set.\n *\n * @example\n *\n * ```ts\n * const first = ISet.create<number>([1, 2]);\n *\n * const second = ISet.create<number>([2, 1]);\n *\n * const third = ISet.create<number>([1, 3]);\n *\n * assert.isTrue(ISet.equal(first, second));\n *\n * assert.isFalse(ISet.equal(first, third));\n * ```\n *\n * @template K The type of the elements.\n * @param a The first ISet instance to compare.\n * @param b The second ISet instance to compare.\n * @returns `true` if the sets contain exactly the same elements, `false`\n * otherwise.\n */\n export const equal = <K extends MapSetKeyType>(\n a: ISet<K>,\n b: ISet<K>,\n ): boolean => a.size === b.size && a.every((e) => b.has(e));\n\n /**\n * Computes the difference between two ISet instances, identifying added and\n * deleted elements.\n *\n * This function performs a set difference operation to determine what\n * elements were added and what elements were deleted when transitioning from\n * the old set to the new set. This is useful for change detection, state\n * management, and synchronization scenarios.\n *\n * **Performance:** O(n + m) where n and m are the sizes of the old and new\n * sets respectively.\n *\n * @example\n *\n * ```ts\n * const previous = ISet.create<string>(['draft', 'review']);\n *\n * const current = ISet.create<string>(['review', 'published']);\n *\n * const { added, deleted } = ISet.diff(previous, current);\n *\n * assert.deepStrictEqual(Array.from(added), ['published']);\n *\n * assert.deepStrictEqual(Array.from(deleted), ['draft']);\n * ```\n *\n * @template K The type of the elements.\n * @param oldSet The original set representing the previous state.\n * @param newSet The new set representing the current state.\n * @returns An object with `added` and `deleted` properties, each containing\n * an ISet of elements that were added or removed respectively.\n */\n export const diff = <K extends MapSetKeyType>(\n oldSet: ISet<K>,\n newSet: ISet<K>,\n ): ReadonlyRecord<'added' | 'deleted', ISet<K>> =>\n ({\n deleted: oldSet.subtract(newSet),\n added: newSet.subtract(oldSet),\n }) as const;\n\n /**\n * Computes the intersection of two ISet instances.\n *\n * Returns a new set containing only the elements that are present in both\n * input sets. This operation is commutative: `intersection(a, b) ===\n * intersection(b, a)`.\n *\n * **Performance:** O(min(n, m)) where n and m are the sizes of the input\n * sets.\n *\n * @example\n *\n * ```ts\n * const left = ISet.create<number>([1, 2, 3]);\n *\n * const right = ISet.create<number>([2, 4]);\n *\n * const overlap = ISet.intersection(left, right);\n *\n * assert.deepStrictEqual(Array.from(overlap), [2]);\n * ```\n *\n * @template K The type of the elements.\n * @param a The first set.\n * @param b The second set.\n * @returns A new ISet instance containing elements common to both sets.\n */\n export const intersection = <K extends MapSetKeyType>(\n a: ISet<K>,\n b: ISet<K>,\n ): ISet<K> => a.intersect(b);\n\n /**\n * Computes the union of two ISet instances.\n *\n * Returns a new set containing all elements that are present in either input\n * set. Duplicate elements are automatically handled since sets only contain\n * unique values. This operation is commutative: `union(a, b) === union(b,\n * a)`.\n *\n * **Performance:** O(n + m) where n and m are the sizes of the input sets.\n *\n * @example\n *\n * ```ts\n * const numbers = ISet.create([1, 2]);\n *\n * const words = ISet.create(['one', 'two']);\n *\n * const union = ISet.union(numbers, words);\n *\n * assert.deepStrictEqual(Array.from(union), [1, 2, 'one', 'two']);\n * ```\n *\n * @template K1 The type of elements in the first set.\n * @template K2 The type of elements in the second set.\n * @param a The first set.\n * @param b The second set.\n * @returns A new ISet instance containing all elements from both sets.\n */\n export const union = <K1 extends MapSetKeyType, K2 extends MapSetKeyType>(\n a: ISet<K1>,\n b: ISet<K2>,\n ): ISet<K1 | K2> => a.union(b);\n}\n\n/**\n * Internal class implementation for ISet providing immutable set operations.\n *\n * This class implements the ISet interface using JavaScript's native Set as the\n * underlying storage mechanism for optimal performance. All mutation operations\n * create new instances rather than modifying the existing set, ensuring\n * immutability.\n *\n * **Implementation Details:**\n *\n * - Uses ReadonlySet<K> internally for type safety and performance\n * - Implements copy-on-write semantics for efficiency\n * - Provides optional debug messaging for development\n *\n * @template K The type of the elements. Must extend MapSetKeyType.\n * @implements ISet\n * @implements Iterable\n * @internal This class should not be used directly. Use ISet.create() instead.\n */\nclass ISetClass<K extends MapSetKeyType> implements ISet<K>, Iterable<K> {\n readonly #set: ReadonlySet<K>;\n readonly #showNotFoundMessage: boolean;\n\n /**\n * Constructs an ISetClass instance with the given elements.\n *\n * @param iterable An iterable of elements to populate the set.\n * @param showNotFoundMessage Whether to log warning messages when operations\n * are performed on non-existent elements. Useful for debugging. Defaults to\n * false for production use.\n * @internal Use ISet.create() instead of calling this constructor directly.\n */\n constructor(iterable: Iterable<K>, showNotFoundMessage: boolean = false) {\n this.#set = new Set(iterable);\n\n this.#showNotFoundMessage = showNotFoundMessage;\n }\n\n /** @inheritdoc */\n get size(): SizeType.Arr {\n return asUint32(this.#set.size);\n }\n\n /** @inheritdoc */\n get isEmpty(): boolean {\n return this.size === 0;\n }\n\n /** @inheritdoc */\n has(key: K | (WidenLiteral<K> & {})): boolean {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, @typescript-eslint/no-unnecessary-type-assertion -- unnecessary only under the strict standard library; the stock one types `has` as taking exactly `K`\n return this.#set.has(key as K);\n }\n\n /** @inheritdoc */\n every<L extends K>(predicate: (key: K) => key is L): this is ISet<L>;\n\n /** @inheritdoc */\n every(predicate: (key: K) => boolean): boolean;\n\n /** @inheritdoc */\n every(predicate: (key: K) => boolean): boolean {\n for (const key of this.values()) {\n if (!predicate(key)) return false;\n }\n\n return true;\n }\n\n /** @inheritdoc */\n some(predicate: (key: K) => boolean): boolean {\n for (const key of this.values()) {\n if (predicate(key)) return true;\n }\n\n return false;\n }\n\n /** @inheritdoc */\n add(key: K): ISet<K> {\n if (this.has(key)) return this;\n\n return ISet.create([...this.#set, key]);\n }\n\n /** @inheritdoc */\n delete(key: K): ISet<K> {\n if (!this.has(key)) {\n if (this.#showNotFoundMessage) {\n const keyStr = unknownToString(key);\n\n console.warn(`ISet.delete: key not found: ${keyStr}`);\n }\n\n return this;\n }\n\n return ISet.create(Array.from(this.#set).filter((k) => !Object.is(k, key)));\n }\n\n /** @inheritdoc */\n withMutations(\n actions: readonly Readonly<\n { type: 'add'; key: K } | { type: 'delete'; key: K }\n >[],\n ): ISet<K> {\n const mut_result = new Set<K>(this.#set);\n\n const updateFn = (\n action: Readonly<{ type: 'add'; key: K } | { type: 'delete'; key: K }>,\n ): void => {\n switch (action.type) {\n case 'delete':\n mut_result.delete(action.key);\n\n break;\n\n case 'add':\n mut_result.add(action.key);\n\n break;\n }\n };\n\n for (const action of actions) {\n updateFn(action);\n }\n\n return ISet.create(mut_result);\n }\n\n /** @inheritdoc */\n map<K2 extends MapSetKeyType>(mapFn: (key: K) => K2): ISet<K2> {\n return ISet.create(this.toArray().map(mapFn));\n }\n\n /** @inheritdoc */\n filter<K2 extends K>(predicate: (key: K) => key is K2): ISet<K2>;\n\n /** @inheritdoc */\n filter(predicate: (key: K) => boolean): ISet<K>;\n\n /** @inheritdoc */\n filter(predicate: (key: K) => boolean): ISet<K> {\n return ISet.create(this.toArray().filter(predicate));\n }\n\n /** @inheritdoc */\n filterNot(predicate: (key: K) => boolean): ISet<K> {\n return ISet.create(this.toArray().filter((e) => !predicate(e)));\n }\n\n /** @inheritdoc */\n forEach(callbackfn: (key: K) => void): void {\n for (const v of this.#set) {\n callbackfn(v);\n }\n }\n\n /** @inheritdoc */\n isSubsetOf(set: ISet<WidenLiteral<K>>): boolean {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return this.every((k) => set.has(k as WidenLiteral<K>));\n }\n\n /** @inheritdoc */\n isSupersetOf(set: ISet<WidenLiteral<K>>): boolean {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return set.every((k) => this.has(k as K));\n }\n\n /** @inheritdoc */\n subtract(set: ISet<K>): ISet<K> {\n return ISet.create(this.toArray().filter((k) => !set.has(k)));\n }\n\n /** @inheritdoc */\n intersect(set: ISet<K>): ISet<K> {\n return ISet.create(this.toArray().filter((k) => set.has(k)));\n }\n\n /** @inheritdoc */\n union<K2 extends MapSetKeyType>(set: ISet<K2>): ISet<K | K2> {\n return ISet.create([...this, ...set]);\n }\n\n /**\n * @example\n *\n * ```ts\n * const set = ISet.create(['first', 'second']);\n *\n * const collected = Array.from(set);\n *\n * assert.deepStrictEqual(collected, ['first', 'second']);\n * ```\n *\n * @inheritdoc\n */\n [Symbol.iterator](): Iterator<K> {\n return this.#set[Symbol.iterator]();\n }\n\n /** @inheritdoc */\n keys(): IterableIterator<K> {\n return this.#set.keys();\n }\n\n /** @inheritdoc */\n values(): IterableIterator<K> {\n return this.#set.values();\n }\n\n /** @inheritdoc */\n entries(): IterableIterator<FixedLengthTuple<2, K>> {\n return this.#set.entries();\n }\n\n /** @inheritdoc */\n toArray(): readonly K[] {\n return Array.from(this.values());\n }\n\n /** @inheritdoc */\n toRawSet(): ReadonlySet<K> {\n return this.#set;\n }\n}\n"],"names":["ISet"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuhBO,IAAU;AAAA,CAAV,CAAUA,KA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3
|
-
import '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import '../number/branded-types/non-positive-int.mjs';
|
|
17
|
-
import '../number/branded-types/non-positive-safe-int.mjs';
|
|
18
|
-
import '../number/branded-types/non-zero-finite-number.mjs';
|
|
19
|
-
import '../number/branded-types/non-zero-int.mjs';
|
|
20
|
-
import '../number/branded-types/non-zero-int16.mjs';
|
|
21
|
-
import '../number/branded-types/non-zero-int32.mjs';
|
|
22
|
-
import '../number/branded-types/non-zero-safe-int.mjs';
|
|
23
|
-
import '../number/branded-types/non-zero-uint16.mjs';
|
|
24
|
-
import '../number/branded-types/non-zero-uint32.mjs';
|
|
25
|
-
import '../number/branded-types/positive-finite-number.mjs';
|
|
26
|
-
import '../number/branded-types/positive-int.mjs';
|
|
27
|
-
import '../number/branded-types/positive-int16.mjs';
|
|
28
|
-
import '../number/branded-types/positive-int32.mjs';
|
|
29
|
-
import '../number/branded-types/positive-safe-int.mjs';
|
|
30
|
-
import '../number/branded-types/positive-uint16.mjs';
|
|
31
|
-
import '../number/branded-types/positive-uint32.mjs';
|
|
32
|
-
import '../number/branded-types/safe-int.mjs';
|
|
33
|
-
import { asSafeUint } from '../number/branded-types/safe-uint.mjs';
|
|
34
|
-
import '../number/branded-types/uint.mjs';
|
|
35
|
-
import '../number/branded-types/uint16.mjs';
|
|
36
|
-
import { asUint32 } from '../number/branded-types/uint32.mjs';
|
|
37
|
-
import '../number/enum/int8.mjs';
|
|
38
|
-
import '../number/enum/uint8.mjs';
|
|
39
|
-
import '../number/num.mjs';
|
|
40
|
-
import '../number/refined-number-utils.mjs';
|
|
1
|
+
import { Optional } from '../functional/index.mjs';
|
|
2
|
+
import { range } from '../iterator/index.mjs';
|
|
3
|
+
import { asSafeUint, asUint32 } from '../number/index.mjs';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
41
16
|
|
|
42
17
|
class QueueClass {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.#mut_capacity = initialCapacity;
|
|
72
|
-
for (const value of initialValues) {
|
|
73
|
-
this.enqueue(value);
|
|
18
|
+
|
|
19
|
+
static #INITIAL_CAPACITY = 8;
|
|
20
|
+
|
|
21
|
+
#mut_buffer;
|
|
22
|
+
|
|
23
|
+
#mut_head;
|
|
24
|
+
|
|
25
|
+
#mut_tail;
|
|
26
|
+
|
|
27
|
+
#mut_size;
|
|
28
|
+
|
|
29
|
+
#mut_capacity;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
constructor(initialValues = []) {
|
|
36
|
+
const initialCapacity = asUint32(Math.max(QueueClass.#INITIAL_CAPACITY, initialValues.length * 2));
|
|
37
|
+
this.#mut_buffer = Array.from({ length: initialCapacity }, () => undefined);
|
|
38
|
+
this.#mut_head = 0;
|
|
39
|
+
this.#mut_tail = 0;
|
|
40
|
+
this.#mut_size = 0;
|
|
41
|
+
this.#mut_capacity = initialCapacity;
|
|
42
|
+
|
|
43
|
+
for (const value of initialValues) {
|
|
44
|
+
this.enqueue(value);
|
|
45
|
+
}
|
|
74
46
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
#resize() {
|
|
53
|
+
const newCapacity = asUint32(this.#mut_capacity * 2);
|
|
54
|
+
const newBuffer = Array.from({ length: newCapacity }, () => undefined);
|
|
55
|
+
|
|
56
|
+
for (const i of range(asSafeUint(this.#mut_size))) {
|
|
57
|
+
const sourceIndex = (this.#mut_head + i) % this.#mut_capacity;
|
|
58
|
+
newBuffer[i] = this.#mut_buffer[sourceIndex];
|
|
59
|
+
}
|
|
60
|
+
this.#mut_buffer = newBuffer;
|
|
61
|
+
this.#mut_head = 0;
|
|
62
|
+
this.#mut_tail = this.#mut_size;
|
|
63
|
+
this.#mut_capacity = newCapacity;
|
|
90
64
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.#mut_capacity = newCapacity;
|
|
95
|
-
}
|
|
96
|
-
/** @inheritdoc */
|
|
97
|
-
get isEmpty() {
|
|
98
|
-
return this.#mut_size === 0;
|
|
99
|
-
}
|
|
100
|
-
/** @inheritdoc */
|
|
101
|
-
get size() {
|
|
102
|
-
return asUint32(this.#mut_size);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Removes and returns the element at the front of the queue (FIFO).
|
|
106
|
-
*
|
|
107
|
-
* This operation removes the element that was added earliest (first-in) and
|
|
108
|
-
* returns it. If the queue is empty, returns `Optional.none`. The operation
|
|
109
|
-
* is guaranteed to be O(1) and does not require any array shifting or
|
|
110
|
-
* copying.
|
|
111
|
-
*
|
|
112
|
-
* **Time Complexity:** O(1) - constant time operation **Space Complexity:**
|
|
113
|
-
* O(1) - no additional memory allocation
|
|
114
|
-
*
|
|
115
|
-
* @returns An Optional containing the removed element, or `Optional.none` if
|
|
116
|
-
* the queue is empty.
|
|
117
|
-
*/
|
|
118
|
-
dequeue() {
|
|
119
|
-
if (this.isEmpty) {
|
|
120
|
-
return none;
|
|
65
|
+
|
|
66
|
+
get isEmpty() {
|
|
67
|
+
return this.#mut_size === 0;
|
|
121
68
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
69
|
+
|
|
70
|
+
get size() {
|
|
71
|
+
return asUint32(this.#mut_size);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
dequeue() {
|
|
88
|
+
if (this.isEmpty) {
|
|
89
|
+
return Optional.none;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const element = this.#mut_buffer[this.#mut_head];
|
|
93
|
+
this.#mut_buffer[this.#mut_head] = undefined;
|
|
94
|
+
this.#mut_head = (this.#mut_head + 1) % this.#mut_capacity;
|
|
95
|
+
this.#mut_size -= 1;
|
|
96
|
+
return Optional.some(element);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
enqueue(value) {
|
|
116
|
+
|
|
117
|
+
if (this.#mut_size === this.#mut_capacity) {
|
|
118
|
+
this.#resize();
|
|
119
|
+
}
|
|
120
|
+
this.#mut_buffer[this.#mut_tail] = value;
|
|
121
|
+
this.#mut_tail = (this.#mut_tail + 1) % this.#mut_capacity;
|
|
122
|
+
this.#mut_size += 1;
|
|
148
123
|
}
|
|
149
|
-
this.#mut_buffer[this.#mut_tail] = value;
|
|
150
|
-
this.#mut_tail = (this.#mut_tail + 1) % this.#mut_capacity;
|
|
151
|
-
this.#mut_size += 1;
|
|
152
|
-
}
|
|
153
124
|
}
|
|
154
|
-
const createQueue = (initialValues) => new QueueClass(initialValues);
|
|
155
125
|
|
|
156
|
-
|
|
157
|
-
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
export const createQueue = (initialValues) => new QueueClass(initialValues);
|
|
189
|
+
//# sourceMappingURL=queue.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.mjs","sources":["../../src/collections/queue.mts"],"sourcesContent":["import { Optional } from '../functional/index.mjs';\nimport { range } from '../iterator/index.mjs';\nimport { asSafeUint, asUint32 } from '../number/index.mjs';\nimport { type SizeType } from '../types.mjs';\n\n/**\n * Interface for a high-performance queue with FIFO (First-In, First-Out)\n * behavior.\n *\n * This interface defines a mutable queue data structure where elements are\n * added to the back and removed from the front, maintaining the order in which\n * they were added. The implementation uses a circular buffer for optimal\n * performance, providing O(1) operations for both enqueue and dequeue\n * operations.\n *\n * **FIFO Behavior:**\n *\n * - **enqueue**: Adds elements to the back of the queue\n * - **dequeue**: Removes and returns elements from the front of the queue\n * - Elements are processed in the exact order they were added\n *\n * **Performance Characteristics:**\n *\n * - Enqueue: O(1) amortized (O(n) when buffer needs resizing)\n * - Dequeue: O(1) always\n * - Size/isEmpty: O(1) always\n * - Memory efficient with automatic garbage collection of removed elements\n *\n * **Use Cases:**\n *\n * - Task scheduling and job queues\n * - Breadth-first search algorithms\n * - Event processing systems\n * - Producer-consumer patterns\n * - Buffer management for streaming data\n *\n * @template T The type of elements stored in the queue.\n */\nexport type Queue<T> = Readonly<{\n /**\n * Checks if the queue is empty.\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n */\n isEmpty: boolean;\n\n /**\n * The number of elements in the queue.\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n */\n size: SizeType.Arr;\n\n /**\n * Removes and returns the element at the front of the queue.\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n *\n * @returns The element at the front of the queue, or `Optional.none` if the\n * queue is empty.\n */\n dequeue: () => Optional<T>;\n\n /**\n * Adds an element to the back of the queue.\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n *\n * @param value The element to add.\n */\n enqueue: (value: T) => void;\n}>;\n\n/**\n * Class implementation for a queue with FIFO (First-In, First-Out) behavior\n * using a circular buffer. This implementation provides O(1) enqueue and\n * dequeue operations by using a fixed-size buffer with head and tail pointers\n * that wrap around when they reach the buffer boundary.\n *\n * The circular buffer automatically resizes when it becomes full, ensuring that\n * the queue can grow to accommodate any number of elements while maintaining\n * efficient operations.\n *\n * @template T The type of elements in the queue.\n * @implements Queue\n */\nclass QueueClass<T> implements Queue<T> {\n /** @internal Initial capacity for new queues. */\n static readonly #INITIAL_CAPACITY = 8;\n\n /** @internal Circular buffer to store queue elements. */\n #mut_buffer: (T | undefined)[];\n\n /** @internal Index of the first element (front of queue). */\n #mut_head: number;\n\n /** @internal Index where the next element will be added (back of queue). */\n #mut_tail: number;\n\n /** @internal Current number of elements in the queue. */\n #mut_size: number;\n\n /** @internal Current capacity of the buffer. */\n #mut_capacity: number;\n\n /**\n * Constructs a new QueueClass instance.\n *\n * @param initialValues Optional initial values to populate the queue.\n */\n constructor(initialValues: readonly T[] = []) {\n const initialCapacity = asUint32(\n Math.max(QueueClass.#INITIAL_CAPACITY, initialValues.length * 2),\n );\n\n this.#mut_buffer = Array.from<unknown, T | undefined>(\n { length: initialCapacity },\n () => undefined,\n );\n\n this.#mut_head = 0;\n\n this.#mut_tail = 0;\n\n this.#mut_size = 0;\n\n this.#mut_capacity = initialCapacity;\n\n // Add initial values\n for (const value of initialValues) {\n this.enqueue(value);\n }\n }\n\n /**\n * @internal\n * Resizes the circular buffer when it becomes full.\n * Doubles the capacity and reorganizes elements to maintain queue order.\n */\n #resize(): void {\n const newCapacity = asUint32(this.#mut_capacity * 2);\n\n const newBuffer = Array.from<unknown, T | undefined>(\n { length: newCapacity },\n () => undefined,\n );\n\n // Copy elements in order from head to tail\n for (const i of range(asSafeUint(this.#mut_size))) {\n const sourceIndex = (this.#mut_head + i) % this.#mut_capacity;\n\n newBuffer[i] = this.#mut_buffer[sourceIndex];\n }\n\n this.#mut_buffer = newBuffer;\n\n this.#mut_head = 0;\n\n this.#mut_tail = this.#mut_size;\n\n this.#mut_capacity = newCapacity;\n }\n\n /** @inheritdoc */\n get isEmpty(): boolean {\n return this.#mut_size === 0;\n }\n\n /** @inheritdoc */\n get size(): SizeType.Arr {\n return asUint32(this.#mut_size);\n }\n\n /**\n * Removes and returns the element at the front of the queue (FIFO).\n *\n * This operation removes the element that was added earliest (first-in) and\n * returns it. If the queue is empty, returns `Optional.none`. The operation\n * is guaranteed to be O(1) and does not require any array shifting or\n * copying.\n *\n * **Time Complexity:** O(1) - constant time operation **Space Complexity:**\n * O(1) - no additional memory allocation\n *\n * @returns An Optional containing the removed element, or `Optional.none` if\n * the queue is empty.\n */\n dequeue(): Optional<T> {\n if (this.isEmpty) {\n return Optional.none;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.#mut_buffer[this.#mut_head]!;\n\n this.#mut_buffer[this.#mut_head] = undefined; // Clear reference for garbage collection\n\n this.#mut_head = (this.#mut_head + 1) % this.#mut_capacity;\n\n this.#mut_size -= 1;\n\n return Optional.some(element);\n }\n\n /**\n * Adds an element to the back of the queue (FIFO).\n *\n * This operation adds the element to the end of the queue, where it will be\n * the last to be dequeued (first-in, first-out ordering). The operation is\n * amortized O(1), meaning it's O(1) for most operations with occasional O(n)\n * when the buffer needs resizing.\n *\n * **Time Complexity:** O(1) amortized - O(n) only when buffer resize is\n * needed **Space Complexity:** O(1) - constant additional memory per element\n *\n * **Buffer Resizing:** When the internal buffer becomes full, it\n * automatically doubles in size and reorganizes elements to maintain the\n * circular buffer structure.\n *\n * @param value The element to add to the back of the queue.\n */\n enqueue(value: T): void {\n // Resize if buffer is full\n if (this.#mut_size === this.#mut_capacity) {\n this.#resize();\n }\n\n this.#mut_buffer[this.#mut_tail] = value;\n\n this.#mut_tail = (this.#mut_tail + 1) % this.#mut_capacity;\n\n this.#mut_size += 1;\n }\n}\n\n/**\n * Creates a new Queue instance with FIFO (First-In, First-Out) behavior using a\n * high-performance circular buffer.\n *\n * This factory function creates an optimized queue implementation that\n * maintains excellent performance characteristics for both enqueue and dequeue\n * operations. The underlying circular buffer automatically resizes to\n * accommodate growing workloads while providing predictable O(1) operations.\n *\n * **Implementation Features:**\n *\n * - **O(1) enqueue operations** (amortized - occasionally O(n) when resizing)\n * - **O(1) dequeue operations** (always)\n * - **Automatic buffer resizing** - starts at 8 elements, doubles when full\n * - **Memory efficient** - garbage collects removed elements immediately\n * - **Circular buffer design** - eliminates need for array shifting operations\n *\n * **Performance Benefits:**\n *\n * - No array copying during normal operations\n * - Minimal memory allocation overhead\n * - Predictable performance under high load\n * - Efficient memory usage with automatic cleanup\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n *\n * @template T The type of elements stored in the queue.\n * @param initialValues Optional array of initial elements to populate the\n * queue. Elements will be dequeued in the same order they appear in the\n * array. If provided, the initial buffer capacity will be at least twice the\n * array length.\n * @returns A new Queue instance optimized for high-performance FIFO operations.\n */\nexport const createQueue = <T,>(initialValues?: readonly T[]): Queue<T> =>\n new QueueClass<T>(initialValues);\n"],"names":["Optional.none","Optional.some"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8MA,MAAM,UAAA,CAAkC;AAAA;AAAA,EAEtC,OAAgB,iBAAA,GAAoB,CAAA;AAAA;AAAA,EAGpC,WAAA;AAAA;AAAA,EAGA,SAAA;AAAA;AAAA,EAGA,SAAA;AAAA;AAAA,EAGA,SAAA;AAAA;AAAA,EAGA,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAA,CAAY,aAAA,GAA8B,EAAC,EAAG;AAC5C,IAAA,MAAM,eAAA,GAAkB,QAAA;AAAA,MACtB,KAAK,GAAA,CAAI,UAAA,CAAW,iBAAA,EAAmB,aAAA,CAAc,SAAS,CAAC;AAAA,KACjE;AAEA,IAAA,IAAA,CAAK,cAAc,KAAA,CAAM,IAAA;AAAA,MACvB,EAAE,QAAQ,eAAA,EAAgB;AAAA,MAC1B,MAAM;AAAA,KACR;AAEA,IAAA,IAAA,CAAK,SAAA,GAAY,CAAA;AAEjB,IAAA,IAAA,CAAK,SAAA,GAAY,CAAA;AAEjB,IAAA,IAAA,CAAK,SAAA,GAAY,CAAA;AAEjB,IAAA,IAAA,CAAK,aAAA,GAAgB,eAAA;AAGrB,IAAA,KAAA,MAAW,SAAS,aAAA,EAAe;AACjC,MAAA,IAAA,CAAK,QAAQ,KAAK,CAAA;AAAA,IACpB;AAA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