ts-data-forge 5.1.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -44
- 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 +8 -8
- package/dist/array/impl/array-utils-search.d.mts +4 -4
- package/dist/array/impl/array-utils-set-op.d.mts +7 -7
- package/dist/array/impl/array-utils-set-op.mjs +7 -7
- package/dist/array/impl/array-utils-size.d.mts +2 -2
- package/dist/array/impl/array-utils-size.mjs +2 -2
- package/dist/array/impl/array-utils-slicing.d.mts +2 -2
- package/dist/array/impl/array-utils-slicing.mjs +2 -2
- package/dist/array/impl/array-utils-validation.d.mts +18 -18
- package/dist/array/impl/array-utils-validation.mjs +14 -14
- package/dist/collections/imap.d.mts +15 -15
- package/dist/collections/imap.mjs +3 -3
- package/dist/collections/iset-mapped.d.mts +19 -19
- package/dist/collections/iset-mapped.mjs +2 -2
- package/dist/collections/iset.d.mts +19 -19
- package/dist/collections/iset.mjs +2 -2
- package/dist/collections/queue.d.mts +25 -25
- package/dist/collections/queue.mjs +5 -5
- package/dist/collections/stack.d.mts +25 -25
- package/dist/collections/stack.mjs +5 -5
- package/dist/functional/match.d.mts +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +2 -2
- 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 +2 -2
- package/dist/functional/optional/impl/optional-is-optional.mjs +2 -2
- package/dist/functional/optional/impl/optional-is-some.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +1 -1
- package/dist/functional/optional/impl/optional-none.d.mts +2 -2
- package/dist/functional/optional/impl/optional-none.mjs +2 -2
- package/dist/functional/optional/impl/optional-some.d.mts +2 -2
- package/dist/functional/optional/impl/optional-some.mjs +2 -2
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +2 -2
- package/dist/functional/optional/impl/optional-to-nullable.mjs +2 -2
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +4 -4
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +2 -2
- package/dist/functional/optional/impl/optional-zip.d.mts +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +1 -1
- package/dist/functional/pipe.d.mts +2 -2
- package/dist/functional/result/impl/result-err.d.mts +1 -1
- package/dist/functional/result/impl/result-err.mjs +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +2 -2
- package/dist/functional/result/impl/result-from-promise.d.mts +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +2 -2
- package/dist/functional/result/impl/result-is-err.mjs +2 -2
- package/dist/functional/result/impl/result-is-ok.d.mts +2 -2
- package/dist/functional/result/impl/result-is-ok.mjs +2 -2
- package/dist/functional/result/impl/result-is-result.d.mts +3 -3
- package/dist/functional/result/impl/result-is-result.mjs +3 -3
- package/dist/functional/result/impl/result-ok.d.mts +1 -1
- package/dist/functional/result/impl/result-ok.mjs +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +4 -4
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +2 -2
- package/dist/functional/result/impl/result-unwrap-err.mjs +2 -2
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +4 -4
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +2 -2
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +3 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +3 -3
- package/dist/globals.d.mts +2 -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/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +1 -1
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +2 -2
- package/dist/guard/key-is-in.mjs +2 -2
- package/dist/json/json.d.mts +21 -21
- package/dist/json/json.mjs +21 -21
- package/dist/number/branded-types/int.d.mts +19 -19
- package/dist/number/branded-types/int.mjs +19 -19
- package/dist/number/branded-types/positive-int.d.mts +20 -20
- package/dist/number/branded-types/positive-int.mjs +20 -20
- package/dist/number/branded-types/positive-safe-int.d.mts +26 -26
- package/dist/number/branded-types/positive-safe-int.mjs +26 -26
- package/dist/number/branded-types/safe-int.d.mts +27 -27
- package/dist/number/branded-types/safe-int.mjs +27 -27
- package/dist/number/branded-types/uint.d.mts +19 -19
- package/dist/number/branded-types/uint.mjs +19 -19
- package/dist/number/num.d.mts +20 -20
- package/dist/number/num.mjs +16 -16
- package/dist/number/refined-number-utils.d.mts +11 -11
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +11 -11
- package/dist/object/object.d.mts +3 -3
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +3 -3
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/tuple.d.mts +3 -3
- package/dist/others/tuple.mjs +3 -3
- package/dist/promise/promise.d.mts +4 -4
- package/dist/promise/promise.mjs +4 -4
- package/package.json +15 -13
- package/src/array/impl/array-utils-creation.test.mts +1 -1
- package/src/array/impl/array-utils-element-access.test.mts +16 -16
- package/src/array/impl/array-utils-modification.mts +38 -19
- package/src/array/impl/array-utils-reducing-value.mts +8 -8
- package/src/array/impl/array-utils-reducing-value.test.mts +23 -31
- package/src/array/impl/array-utils-search.mts +4 -4
- package/src/array/impl/array-utils-search.test.mts +10 -10
- package/src/array/impl/array-utils-set-op.mts +7 -7
- package/src/array/impl/array-utils-set-op.test.mts +13 -13
- package/src/array/impl/array-utils-size.mts +2 -2
- package/src/array/impl/array-utils-slicing.mts +2 -2
- package/src/array/impl/array-utils-transformation.test.mts +2 -2
- package/src/array/impl/array-utils-validation.mts +18 -18
- package/src/array/impl/array-utils-validation.test.mts +80 -78
- package/src/array/impl/array.test.mts +6 -6
- package/src/collections/imap-mapped.test.mts +16 -18
- package/src/collections/imap.mts +15 -15
- package/src/collections/imap.test.mts +31 -31
- package/src/collections/iset-mapped.mts +19 -19
- package/src/collections/iset-mapped.test.mts +52 -52
- package/src/collections/iset.mts +19 -19
- package/src/collections/iset.test.mts +130 -130
- package/src/collections/queue.mts +25 -25
- package/src/collections/queue.test.mts +33 -35
- package/src/collections/stack.mts +25 -25
- package/src/collections/stack.test.mts +15 -15
- package/src/functional/match.mts +1 -1
- package/src/functional/optional/impl/optional-expect-to-be.mts +2 -2
- package/src/functional/optional/impl/optional-is-none.mts +1 -1
- package/src/functional/optional/impl/optional-is-optional.mts +2 -2
- package/src/functional/optional/impl/optional-is-some.mts +1 -1
- package/src/functional/optional/impl/optional-none.mts +2 -2
- package/src/functional/optional/impl/optional-some.mts +2 -2
- package/src/functional/optional/impl/optional-to-nullable.mts +2 -2
- package/src/functional/optional/impl/optional-unwrap-or.mts +4 -4
- package/src/functional/optional/impl/optional-unwrap-throw.mts +1 -1
- package/src/functional/optional/impl/optional-unwrap.mts +2 -2
- package/src/functional/optional/impl/optional-zip.mts +1 -1
- package/src/functional/optional.test.mts +53 -54
- package/src/functional/pipe.mts +2 -2
- package/src/functional/pipe.test.mts +4 -4
- package/src/functional/result/impl/result-err.mts +1 -1
- package/src/functional/result/impl/result-expect-to-be.mts +2 -2
- package/src/functional/result/impl/result-from-promise.mts +1 -1
- package/src/functional/result/impl/result-from-throwable.mts +1 -1
- package/src/functional/result/impl/result-is-err.mts +2 -2
- package/src/functional/result/impl/result-is-ok.mts +2 -2
- package/src/functional/result/impl/result-is-result.mts +3 -3
- package/src/functional/result/impl/result-ok.mts +1 -1
- package/src/functional/result/impl/result-unwrap-err-or.mts +4 -4
- package/src/functional/result/impl/result-unwrap-err-throw.mts +1 -1
- package/src/functional/result/impl/result-unwrap-err.mts +2 -2
- package/src/functional/result/impl/result-unwrap-ok-or.mts +4 -4
- package/src/functional/result/impl/result-unwrap-ok.mts +2 -2
- package/src/functional/result/impl/result-unwrap-throw.mts +1 -1
- package/src/functional/result.test.mts +94 -152
- package/src/functional/ternary-result/impl/ternary-result-err.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +3 -3
- package/src/functional/ternary-result.test.mts +8 -8
- package/src/globals.d.mts +2 -1
- package/src/guard/has-key.mts +8 -5
- package/src/guard/has-key.test.mts +0 -5
- package/src/guard/is-error.test.mts +143 -0
- package/src/guard/is-non-empty-string.test.mts +24 -24
- package/src/guard/is-non-null-object.test.mts +26 -26
- package/src/guard/is-primitive.test.mts +28 -28
- package/src/guard/is-record.mts +1 -2
- package/src/guard/is-record.test.mts +57 -67
- package/src/guard/is-type.test.mts +151 -155
- package/src/guard/key-is-in.mts +2 -2
- package/src/guard/key-is-in.test.mts +2 -2
- package/src/json/json.mts +21 -21
- package/src/json/json.test.mts +135 -174
- package/src/number/branded-types/finite-number.test.mts +13 -11
- package/src/number/branded-types/int.mts +19 -19
- package/src/number/branded-types/int.test.mts +14 -14
- package/src/number/branded-types/int16.test.mts +16 -16
- package/src/number/branded-types/int32.test.mts +16 -16
- package/src/number/branded-types/non-negative-finite-number.test.mts +12 -12
- package/src/number/branded-types/non-negative-int16.test.mts +16 -16
- package/src/number/branded-types/non-negative-int32.test.mts +16 -16
- package/src/number/branded-types/non-zero-finite-number.test.mts +14 -14
- package/src/number/branded-types/non-zero-int.test.mts +19 -19
- package/src/number/branded-types/non-zero-int16.test.mts +16 -16
- package/src/number/branded-types/non-zero-int32.test.mts +16 -16
- package/src/number/branded-types/non-zero-safe-int.test.mts +23 -23
- package/src/number/branded-types/non-zero-uint16.test.mts +16 -16
- package/src/number/branded-types/non-zero-uint32.test.mts +16 -16
- package/src/number/branded-types/positive-finite-number.test.mts +14 -14
- package/src/number/branded-types/positive-int.mts +20 -20
- package/src/number/branded-types/positive-int.test.mts +17 -17
- package/src/number/branded-types/positive-int16.test.mts +15 -15
- package/src/number/branded-types/positive-int32.test.mts +15 -15
- package/src/number/branded-types/positive-safe-int.mts +26 -26
- package/src/number/branded-types/positive-safe-int.test.mts +19 -19
- package/src/number/branded-types/positive-uint16.test.mts +16 -16
- package/src/number/branded-types/positive-uint32.test.mts +16 -16
- package/src/number/branded-types/safe-int.mts +27 -27
- package/src/number/branded-types/safe-int.test.mts +18 -18
- package/src/number/branded-types/safe-uint.test.mts +17 -17
- package/src/number/branded-types/uint.mts +19 -19
- package/src/number/branded-types/uint.test.mts +15 -15
- package/src/number/branded-types/uint16.test.mts +15 -15
- package/src/number/branded-types/uint32.test.mts +15 -15
- package/src/number/enum/int8.test.mts +1 -1
- package/src/number/enum/uint8.test.mts +1 -1
- package/src/number/num.mts +20 -20
- package/src/number/num.test.mts +26 -26
- package/src/number/refined-number-utils.mts +13 -13
- package/src/object/object.mts +4 -3
- package/src/object/object.test.mts +6 -6
- package/src/others/cast-mutable.test.mts +1 -1
- package/src/others/cast-readonly.test.mts +4 -4
- package/src/others/if-then.test.mts +24 -24
- package/src/others/tuple.mts +3 -3
- package/src/promise/promise.mts +4 -4
- package/src/promise/promise.test.mts +7 -13
|
@@ -44,17 +44,17 @@ export type Queue<T> = Readonly<{
|
|
|
44
44
|
* ```ts
|
|
45
45
|
* const queue = createQueue<number>();
|
|
46
46
|
*
|
|
47
|
-
* assert.
|
|
47
|
+
* assert.isTrue(queue.isEmpty);
|
|
48
48
|
*
|
|
49
|
-
* assert(queue.size === 0);
|
|
49
|
+
* assert.isTrue(queue.size === 0);
|
|
50
50
|
*
|
|
51
51
|
* queue.enqueue(1);
|
|
52
52
|
*
|
|
53
53
|
* queue.enqueue(2);
|
|
54
54
|
*
|
|
55
|
-
* assert.
|
|
55
|
+
* assert.isFalse(queue.isEmpty);
|
|
56
56
|
*
|
|
57
|
-
* assert(queue.size === 2);
|
|
57
|
+
* assert.isTrue(queue.size === 2);
|
|
58
58
|
*
|
|
59
59
|
* assert.deepStrictEqual(queue.dequeue(), Optional.some(1));
|
|
60
60
|
*
|
|
@@ -64,7 +64,7 @@ export type Queue<T> = Readonly<{
|
|
|
64
64
|
*
|
|
65
65
|
* const seededQueue = createQueue(['first', 'second']);
|
|
66
66
|
*
|
|
67
|
-
* assert(seededQueue.size === 2);
|
|
67
|
+
* assert.isTrue(seededQueue.size === 2);
|
|
68
68
|
*
|
|
69
69
|
* assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));
|
|
70
70
|
*
|
|
@@ -81,17 +81,17 @@ export type Queue<T> = Readonly<{
|
|
|
81
81
|
* ```ts
|
|
82
82
|
* const queue = createQueue<number>();
|
|
83
83
|
*
|
|
84
|
-
* assert.
|
|
84
|
+
* assert.isTrue(queue.isEmpty);
|
|
85
85
|
*
|
|
86
|
-
* assert(queue.size === 0);
|
|
86
|
+
* assert.isTrue(queue.size === 0);
|
|
87
87
|
*
|
|
88
88
|
* queue.enqueue(1);
|
|
89
89
|
*
|
|
90
90
|
* queue.enqueue(2);
|
|
91
91
|
*
|
|
92
|
-
* assert.
|
|
92
|
+
* assert.isFalse(queue.isEmpty);
|
|
93
93
|
*
|
|
94
|
-
* assert(queue.size === 2);
|
|
94
|
+
* assert.isTrue(queue.size === 2);
|
|
95
95
|
*
|
|
96
96
|
* assert.deepStrictEqual(queue.dequeue(), Optional.some(1));
|
|
97
97
|
*
|
|
@@ -101,7 +101,7 @@ export type Queue<T> = Readonly<{
|
|
|
101
101
|
*
|
|
102
102
|
* const seededQueue = createQueue(['first', 'second']);
|
|
103
103
|
*
|
|
104
|
-
* assert(seededQueue.size === 2);
|
|
104
|
+
* assert.isTrue(seededQueue.size === 2);
|
|
105
105
|
*
|
|
106
106
|
* assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));
|
|
107
107
|
*
|
|
@@ -118,17 +118,17 @@ export type Queue<T> = Readonly<{
|
|
|
118
118
|
* ```ts
|
|
119
119
|
* const queue = createQueue<number>();
|
|
120
120
|
*
|
|
121
|
-
* assert.
|
|
121
|
+
* assert.isTrue(queue.isEmpty);
|
|
122
122
|
*
|
|
123
|
-
* assert(queue.size === 0);
|
|
123
|
+
* assert.isTrue(queue.size === 0);
|
|
124
124
|
*
|
|
125
125
|
* queue.enqueue(1);
|
|
126
126
|
*
|
|
127
127
|
* queue.enqueue(2);
|
|
128
128
|
*
|
|
129
|
-
* assert.
|
|
129
|
+
* assert.isFalse(queue.isEmpty);
|
|
130
130
|
*
|
|
131
|
-
* assert(queue.size === 2);
|
|
131
|
+
* assert.isTrue(queue.size === 2);
|
|
132
132
|
*
|
|
133
133
|
* assert.deepStrictEqual(queue.dequeue(), Optional.some(1));
|
|
134
134
|
*
|
|
@@ -138,7 +138,7 @@ export type Queue<T> = Readonly<{
|
|
|
138
138
|
*
|
|
139
139
|
* const seededQueue = createQueue(['first', 'second']);
|
|
140
140
|
*
|
|
141
|
-
* assert(seededQueue.size === 2);
|
|
141
|
+
* assert.isTrue(seededQueue.size === 2);
|
|
142
142
|
*
|
|
143
143
|
* assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));
|
|
144
144
|
*
|
|
@@ -158,17 +158,17 @@ export type Queue<T> = Readonly<{
|
|
|
158
158
|
* ```ts
|
|
159
159
|
* const queue = createQueue<number>();
|
|
160
160
|
*
|
|
161
|
-
* assert.
|
|
161
|
+
* assert.isTrue(queue.isEmpty);
|
|
162
162
|
*
|
|
163
|
-
* assert(queue.size === 0);
|
|
163
|
+
* assert.isTrue(queue.size === 0);
|
|
164
164
|
*
|
|
165
165
|
* queue.enqueue(1);
|
|
166
166
|
*
|
|
167
167
|
* queue.enqueue(2);
|
|
168
168
|
*
|
|
169
|
-
* assert.
|
|
169
|
+
* assert.isFalse(queue.isEmpty);
|
|
170
170
|
*
|
|
171
|
-
* assert(queue.size === 2);
|
|
171
|
+
* assert.isTrue(queue.size === 2);
|
|
172
172
|
*
|
|
173
173
|
* assert.deepStrictEqual(queue.dequeue(), Optional.some(1));
|
|
174
174
|
*
|
|
@@ -178,7 +178,7 @@ export type Queue<T> = Readonly<{
|
|
|
178
178
|
*
|
|
179
179
|
* const seededQueue = createQueue(['first', 'second']);
|
|
180
180
|
*
|
|
181
|
-
* assert(seededQueue.size === 2);
|
|
181
|
+
* assert.isTrue(seededQueue.size === 2);
|
|
182
182
|
*
|
|
183
183
|
* assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));
|
|
184
184
|
*
|
|
@@ -381,17 +381,17 @@ class QueueClass<T> implements Queue<T> {
|
|
|
381
381
|
* ```ts
|
|
382
382
|
* const queue = createQueue<number>();
|
|
383
383
|
*
|
|
384
|
-
* assert.
|
|
384
|
+
* assert.isTrue(queue.isEmpty);
|
|
385
385
|
*
|
|
386
|
-
* assert(queue.size === 0);
|
|
386
|
+
* assert.isTrue(queue.size === 0);
|
|
387
387
|
*
|
|
388
388
|
* queue.enqueue(1);
|
|
389
389
|
*
|
|
390
390
|
* queue.enqueue(2);
|
|
391
391
|
*
|
|
392
|
-
* assert.
|
|
392
|
+
* assert.isFalse(queue.isEmpty);
|
|
393
393
|
*
|
|
394
|
-
* assert(queue.size === 2);
|
|
394
|
+
* assert.isTrue(queue.size === 2);
|
|
395
395
|
*
|
|
396
396
|
* assert.deepStrictEqual(queue.dequeue(), Optional.some(1));
|
|
397
397
|
*
|
|
@@ -401,7 +401,7 @@ class QueueClass<T> implements Queue<T> {
|
|
|
401
401
|
*
|
|
402
402
|
* const seededQueue = createQueue(['first', 'second']);
|
|
403
403
|
*
|
|
404
|
-
* assert(seededQueue.size === 2);
|
|
404
|
+
* assert.isTrue(seededQueue.size === 2);
|
|
405
405
|
*
|
|
406
406
|
* assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));
|
|
407
407
|
*
|
|
@@ -9,7 +9,7 @@ describe('Queue test', () => {
|
|
|
9
9
|
test('should be empty if initialized without values', () => {
|
|
10
10
|
const q = createQueue();
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
assert.isTrue(q.isEmpty);
|
|
13
13
|
|
|
14
14
|
expect(q.size).toBe(0);
|
|
15
15
|
});
|
|
@@ -17,7 +17,7 @@ describe('Queue test', () => {
|
|
|
17
17
|
test('should not be empty if initialized with values', () => {
|
|
18
18
|
const q = createQueue([1, 2, 3]);
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
assert.isFalse(q.isEmpty);
|
|
21
21
|
|
|
22
22
|
expect(q.size).toBe(3);
|
|
23
23
|
});
|
|
@@ -34,7 +34,7 @@ describe('Queue test', () => {
|
|
|
34
34
|
test('should increase size and not be empty after enqueueing to an empty queue', () => {
|
|
35
35
|
mut_q.enqueue(1);
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
assert.isFalse(mut_q.isEmpty);
|
|
38
38
|
|
|
39
39
|
expect(mut_q.size).toBe(1);
|
|
40
40
|
});
|
|
@@ -54,9 +54,9 @@ describe('Queue test', () => {
|
|
|
54
54
|
|
|
55
55
|
const result = q.dequeue();
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
assert.isTrue(Optional.isNone(result));
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
assert.isTrue(q.isEmpty);
|
|
60
60
|
|
|
61
61
|
expect(q.size).toBe(0);
|
|
62
62
|
});
|
|
@@ -68,7 +68,7 @@ describe('Queue test', () => {
|
|
|
68
68
|
|
|
69
69
|
const result1 = q.dequeue(); // Dequeues 1 (first element)
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
assert.isTrue(Optional.isSome(result1));
|
|
72
72
|
|
|
73
73
|
if (Optional.isSome(result1)) {
|
|
74
74
|
expect(result1.value).toBe(1);
|
|
@@ -78,7 +78,7 @@ describe('Queue test', () => {
|
|
|
78
78
|
|
|
79
79
|
const result2 = q.dequeue(); // Dequeues 2
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
assert.isTrue(Optional.isSome(result2));
|
|
82
82
|
|
|
83
83
|
if (Optional.isSome(result2)) {
|
|
84
84
|
expect(result2.value).toBe(2);
|
|
@@ -94,13 +94,13 @@ describe('Queue test', () => {
|
|
|
94
94
|
|
|
95
95
|
q.dequeue(); // Dequeues 2
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
assert.isTrue(q.isEmpty);
|
|
98
98
|
|
|
99
99
|
expect(q.size).toBe(0);
|
|
100
100
|
|
|
101
101
|
const result = q.dequeue(); // Dequeue from empty
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
assert.isTrue(Optional.isNone(result));
|
|
104
104
|
});
|
|
105
105
|
});
|
|
106
106
|
|
|
@@ -118,27 +118,27 @@ describe('Queue test', () => {
|
|
|
118
118
|
|
|
119
119
|
let mut_result = q.dequeue(); // Dequeues 1 (first in)
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
assert.isTrue(Optional.isSome(mut_result) && mut_result.value === 1);
|
|
122
122
|
|
|
123
123
|
expect(q.size).toBe(2);
|
|
124
124
|
|
|
125
125
|
mut_result = q.dequeue(); // Dequeues 2
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
assert.isTrue(Optional.isSome(mut_result) && mut_result.value === 2);
|
|
128
128
|
|
|
129
129
|
expect(q.size).toBe(1);
|
|
130
130
|
|
|
131
131
|
mut_result = q.dequeue(); // Dequeues 3
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
assert.isTrue(Optional.isSome(mut_result) && mut_result.value === 3);
|
|
134
134
|
|
|
135
135
|
expect(q.size).toBe(0);
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
assert.isTrue(q.isEmpty);
|
|
138
138
|
|
|
139
139
|
mut_result = q.dequeue();
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
assert.isTrue(Optional.isNone(mut_result));
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
test('initial values are dequeued in the same order (FIFO)', () => {
|
|
@@ -148,17 +148,17 @@ describe('Queue test', () => {
|
|
|
148
148
|
|
|
149
149
|
const result1 = q.dequeue(); // Dequeues 1 (first element)
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
assert.isTrue(Optional.isSome(result1) && result1.value === 1);
|
|
152
152
|
|
|
153
153
|
const result2 = q.dequeue(); // Dequeues 2
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
assert.isTrue(Optional.isSome(result2) && result2.value === 2);
|
|
156
156
|
|
|
157
157
|
const result3 = q.dequeue(); // Dequeues 3
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
assert.isTrue(Optional.isSome(result3) && result3.value === 3);
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
assert.isTrue(q.isEmpty);
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
test('mixed enqueue and dequeue operations maintain FIFO order', () => {
|
|
@@ -170,7 +170,7 @@ describe('Queue test', () => {
|
|
|
170
170
|
|
|
171
171
|
const result1 = q.dequeue();
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
assert.isTrue(Optional.isSome(result1) && result1.value === 'A');
|
|
174
174
|
|
|
175
175
|
q.enqueue('C');
|
|
176
176
|
|
|
@@ -178,17 +178,17 @@ describe('Queue test', () => {
|
|
|
178
178
|
|
|
179
179
|
const result2 = q.dequeue();
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
assert.isTrue(Optional.isSome(result2) && result2.value === 'B');
|
|
182
182
|
|
|
183
183
|
const result3 = q.dequeue();
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
assert.isTrue(Optional.isSome(result3) && result3.value === 'C');
|
|
186
186
|
|
|
187
187
|
const result4 = q.dequeue();
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
assert.isTrue(Optional.isSome(result4) && result4.value === 'D');
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
assert.isTrue(q.isEmpty);
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
194
|
|
|
@@ -226,7 +226,7 @@ describe('Queue test', () => {
|
|
|
226
226
|
|
|
227
227
|
expect(Optional.unwrap(q.dequeue())).toBe(8);
|
|
228
228
|
|
|
229
|
-
|
|
229
|
+
assert.isTrue(q.isEmpty);
|
|
230
230
|
});
|
|
231
231
|
|
|
232
232
|
test('should automatically resize when buffer becomes full', () => {
|
|
@@ -243,10 +243,10 @@ describe('Queue test', () => {
|
|
|
243
243
|
for (const i of range(1, 21)) {
|
|
244
244
|
const result = q.dequeue();
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
assert.isTrue(Optional.isSome(result) && result.value === i);
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
|
|
249
|
+
assert.isTrue(q.isEmpty);
|
|
250
250
|
});
|
|
251
251
|
|
|
252
252
|
test('should handle multiple resize operations', () => {
|
|
@@ -280,7 +280,7 @@ describe('Queue test', () => {
|
|
|
280
280
|
expect(Optional.unwrap(q.dequeue())).toBe(i);
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
-
|
|
283
|
+
assert.isTrue(q.isEmpty);
|
|
284
284
|
});
|
|
285
285
|
|
|
286
286
|
test('should handle edge case of single element operations', () => {
|
|
@@ -294,11 +294,9 @@ describe('Queue test', () => {
|
|
|
294
294
|
|
|
295
295
|
const result = q.dequeue();
|
|
296
296
|
|
|
297
|
-
|
|
298
|
-
true,
|
|
299
|
-
);
|
|
297
|
+
assert.isTrue(Optional.isSome(result) && result.value === `item-${i}`);
|
|
300
298
|
|
|
301
|
-
|
|
299
|
+
assert.isTrue(q.isEmpty);
|
|
302
300
|
}
|
|
303
301
|
});
|
|
304
302
|
|
|
@@ -314,7 +312,7 @@ describe('Queue test', () => {
|
|
|
314
312
|
expect(Optional.unwrap(q.dequeue())).toBe(i);
|
|
315
313
|
}
|
|
316
314
|
|
|
317
|
-
|
|
315
|
+
assert.isTrue(q.isEmpty);
|
|
318
316
|
});
|
|
319
317
|
|
|
320
318
|
test('should properly clean up references for garbage collection', () => {
|
|
@@ -331,17 +329,17 @@ describe('Queue test', () => {
|
|
|
331
329
|
for (const i of range(0, 5)) {
|
|
332
330
|
const result = q.dequeue();
|
|
333
331
|
|
|
334
|
-
|
|
332
|
+
assert.isTrue(Optional.isSome(result) && result.value.id === i);
|
|
335
333
|
}
|
|
336
334
|
|
|
337
335
|
// Remaining objects should still be accessible
|
|
338
336
|
for (const i of range(5, 10)) {
|
|
339
337
|
const result = q.dequeue();
|
|
340
338
|
|
|
341
|
-
|
|
339
|
+
assert.isTrue(Optional.isSome(result) && result.value.id === i);
|
|
342
340
|
}
|
|
343
341
|
|
|
344
|
-
|
|
342
|
+
assert.isTrue(q.isEmpty);
|
|
345
343
|
});
|
|
346
344
|
});
|
|
347
345
|
});
|
|
@@ -44,18 +44,18 @@ export type Stack<T> = Readonly<{
|
|
|
44
44
|
* ```ts
|
|
45
45
|
* const stack = createStack<string>();
|
|
46
46
|
*
|
|
47
|
-
* assert.
|
|
47
|
+
* assert.isTrue(stack.isEmpty);
|
|
48
48
|
*
|
|
49
|
-
* assert(stack.size === 0);
|
|
49
|
+
* assert.isTrue(stack.size === 0);
|
|
50
50
|
*
|
|
51
51
|
* stack.push('first');
|
|
52
52
|
*
|
|
53
53
|
* // eslint-disable-next-line unicorn/prefer-single-call
|
|
54
54
|
* stack.push('second');
|
|
55
55
|
*
|
|
56
|
-
* assert.
|
|
56
|
+
* assert.isFalse(stack.isEmpty);
|
|
57
57
|
*
|
|
58
|
-
* assert(stack.size === 2);
|
|
58
|
+
* assert.isTrue(stack.size === 2);
|
|
59
59
|
*
|
|
60
60
|
* assert.deepStrictEqual(stack.pop(), Optional.some('second'));
|
|
61
61
|
*
|
|
@@ -65,7 +65,7 @@ export type Stack<T> = Readonly<{
|
|
|
65
65
|
*
|
|
66
66
|
* const seededStack = createStack([10, 20, 30]);
|
|
67
67
|
*
|
|
68
|
-
* assert(seededStack.size === 3);
|
|
68
|
+
* assert.isTrue(seededStack.size === 3);
|
|
69
69
|
*
|
|
70
70
|
* assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
|
|
71
71
|
* ```
|
|
@@ -80,18 +80,18 @@ export type Stack<T> = Readonly<{
|
|
|
80
80
|
* ```ts
|
|
81
81
|
* const stack = createStack<string>();
|
|
82
82
|
*
|
|
83
|
-
* assert.
|
|
83
|
+
* assert.isTrue(stack.isEmpty);
|
|
84
84
|
*
|
|
85
|
-
* assert(stack.size === 0);
|
|
85
|
+
* assert.isTrue(stack.size === 0);
|
|
86
86
|
*
|
|
87
87
|
* stack.push('first');
|
|
88
88
|
*
|
|
89
89
|
* // eslint-disable-next-line unicorn/prefer-single-call
|
|
90
90
|
* stack.push('second');
|
|
91
91
|
*
|
|
92
|
-
* assert.
|
|
92
|
+
* assert.isFalse(stack.isEmpty);
|
|
93
93
|
*
|
|
94
|
-
* assert(stack.size === 2);
|
|
94
|
+
* assert.isTrue(stack.size === 2);
|
|
95
95
|
*
|
|
96
96
|
* assert.deepStrictEqual(stack.pop(), Optional.some('second'));
|
|
97
97
|
*
|
|
@@ -101,7 +101,7 @@ export type Stack<T> = Readonly<{
|
|
|
101
101
|
*
|
|
102
102
|
* const seededStack = createStack([10, 20, 30]);
|
|
103
103
|
*
|
|
104
|
-
* assert(seededStack.size === 3);
|
|
104
|
+
* assert.isTrue(seededStack.size === 3);
|
|
105
105
|
*
|
|
106
106
|
* assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
|
|
107
107
|
* ```
|
|
@@ -116,18 +116,18 @@ export type Stack<T> = Readonly<{
|
|
|
116
116
|
* ```ts
|
|
117
117
|
* const stack = createStack<string>();
|
|
118
118
|
*
|
|
119
|
-
* assert.
|
|
119
|
+
* assert.isTrue(stack.isEmpty);
|
|
120
120
|
*
|
|
121
|
-
* assert(stack.size === 0);
|
|
121
|
+
* assert.isTrue(stack.size === 0);
|
|
122
122
|
*
|
|
123
123
|
* stack.push('first');
|
|
124
124
|
*
|
|
125
125
|
* // eslint-disable-next-line unicorn/prefer-single-call
|
|
126
126
|
* stack.push('second');
|
|
127
127
|
*
|
|
128
|
-
* assert.
|
|
128
|
+
* assert.isFalse(stack.isEmpty);
|
|
129
129
|
*
|
|
130
|
-
* assert(stack.size === 2);
|
|
130
|
+
* assert.isTrue(stack.size === 2);
|
|
131
131
|
*
|
|
132
132
|
* assert.deepStrictEqual(stack.pop(), Optional.some('second'));
|
|
133
133
|
*
|
|
@@ -137,7 +137,7 @@ export type Stack<T> = Readonly<{
|
|
|
137
137
|
*
|
|
138
138
|
* const seededStack = createStack([10, 20, 30]);
|
|
139
139
|
*
|
|
140
|
-
* assert(seededStack.size === 3);
|
|
140
|
+
* assert.isTrue(seededStack.size === 3);
|
|
141
141
|
*
|
|
142
142
|
* assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
|
|
143
143
|
* ```
|
|
@@ -155,18 +155,18 @@ export type Stack<T> = Readonly<{
|
|
|
155
155
|
* ```ts
|
|
156
156
|
* const stack = createStack<string>();
|
|
157
157
|
*
|
|
158
|
-
* assert.
|
|
158
|
+
* assert.isTrue(stack.isEmpty);
|
|
159
159
|
*
|
|
160
|
-
* assert(stack.size === 0);
|
|
160
|
+
* assert.isTrue(stack.size === 0);
|
|
161
161
|
*
|
|
162
162
|
* stack.push('first');
|
|
163
163
|
*
|
|
164
164
|
* // eslint-disable-next-line unicorn/prefer-single-call
|
|
165
165
|
* stack.push('second');
|
|
166
166
|
*
|
|
167
|
-
* assert.
|
|
167
|
+
* assert.isFalse(stack.isEmpty);
|
|
168
168
|
*
|
|
169
|
-
* assert(stack.size === 2);
|
|
169
|
+
* assert.isTrue(stack.size === 2);
|
|
170
170
|
*
|
|
171
171
|
* assert.deepStrictEqual(stack.pop(), Optional.some('second'));
|
|
172
172
|
*
|
|
@@ -176,7 +176,7 @@ export type Stack<T> = Readonly<{
|
|
|
176
176
|
*
|
|
177
177
|
* const seededStack = createStack([10, 20, 30]);
|
|
178
178
|
*
|
|
179
|
-
* assert(seededStack.size === 3);
|
|
179
|
+
* assert.isTrue(seededStack.size === 3);
|
|
180
180
|
*
|
|
181
181
|
* assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
|
|
182
182
|
* ```
|
|
@@ -356,18 +356,18 @@ class StackClass<T> implements Stack<T> {
|
|
|
356
356
|
* ```ts
|
|
357
357
|
* const stack = createStack<string>();
|
|
358
358
|
*
|
|
359
|
-
* assert.
|
|
359
|
+
* assert.isTrue(stack.isEmpty);
|
|
360
360
|
*
|
|
361
|
-
* assert(stack.size === 0);
|
|
361
|
+
* assert.isTrue(stack.size === 0);
|
|
362
362
|
*
|
|
363
363
|
* stack.push('first');
|
|
364
364
|
*
|
|
365
365
|
* // eslint-disable-next-line unicorn/prefer-single-call
|
|
366
366
|
* stack.push('second');
|
|
367
367
|
*
|
|
368
|
-
* assert.
|
|
368
|
+
* assert.isFalse(stack.isEmpty);
|
|
369
369
|
*
|
|
370
|
-
* assert(stack.size === 2);
|
|
370
|
+
* assert.isTrue(stack.size === 2);
|
|
371
371
|
*
|
|
372
372
|
* assert.deepStrictEqual(stack.pop(), Optional.some('second'));
|
|
373
373
|
*
|
|
@@ -377,7 +377,7 @@ class StackClass<T> implements Stack<T> {
|
|
|
377
377
|
*
|
|
378
378
|
* const seededStack = createStack([10, 20, 30]);
|
|
379
379
|
*
|
|
380
|
-
* assert(seededStack.size === 3);
|
|
380
|
+
* assert.isTrue(seededStack.size === 3);
|
|
381
381
|
*
|
|
382
382
|
* assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
|
|
383
383
|
* ```
|
|
@@ -31,7 +31,7 @@ describe('Stack test', () => {
|
|
|
31
31
|
test('should be empty when created without initial values', () => {
|
|
32
32
|
const stack = createStack<string>();
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
assert.isTrue(stack.isEmpty);
|
|
35
35
|
|
|
36
36
|
expect(stack.size).toBe(0);
|
|
37
37
|
});
|
|
@@ -39,7 +39,7 @@ describe('Stack test', () => {
|
|
|
39
39
|
test('should create with initial values', () => {
|
|
40
40
|
const stack = createStack<number>([1, 2, 3]);
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
assert.isFalse(stack.isEmpty);
|
|
43
43
|
|
|
44
44
|
expect(stack.size).toBe(3);
|
|
45
45
|
|
|
@@ -50,7 +50,7 @@ describe('Stack test', () => {
|
|
|
50
50
|
|
|
51
51
|
expect(Optional.unwrap(stack.pop())).toBe(1);
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
assert.isTrue(stack.isEmpty);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
test('should implement LIFO behavior correctly', () => {
|
|
@@ -66,7 +66,7 @@ describe('Stack test', () => {
|
|
|
66
66
|
|
|
67
67
|
expect(stack.size).toBe(3);
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
assert.isFalse(stack.isEmpty);
|
|
70
70
|
|
|
71
71
|
// LIFO: Last In, First Out
|
|
72
72
|
expect(Optional.unwrap(stack.pop())).toBe('third');
|
|
@@ -75,7 +75,7 @@ describe('Stack test', () => {
|
|
|
75
75
|
|
|
76
76
|
expect(Optional.unwrap(stack.pop())).toBe('first');
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
assert.isTrue(stack.isEmpty);
|
|
79
79
|
|
|
80
80
|
expect(stack.size).toBe(0);
|
|
81
81
|
});
|
|
@@ -85,9 +85,9 @@ describe('Stack test', () => {
|
|
|
85
85
|
|
|
86
86
|
const result = stack.pop();
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
assert.isTrue(Optional.isNone(result));
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
assert.isTrue(stack.isEmpty);
|
|
91
91
|
|
|
92
92
|
expect(stack.size).toBe(0);
|
|
93
93
|
});
|
|
@@ -121,7 +121,7 @@ describe('Stack test', () => {
|
|
|
121
121
|
|
|
122
122
|
expect(stack.size).toBe(0);
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
assert.isTrue(stack.isEmpty);
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
test('should handle mixed push and pop operations', () => {
|
|
@@ -145,7 +145,7 @@ describe('Stack test', () => {
|
|
|
145
145
|
|
|
146
146
|
expect(Optional.unwrap(stack.pop())).toBe('a');
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
assert.isTrue(stack.isEmpty);
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
test('should work with object types', () => {
|
|
@@ -166,7 +166,7 @@ describe('Stack test', () => {
|
|
|
166
166
|
|
|
167
167
|
assert.deepStrictEqual(Optional.unwrap(stack.pop()), item1);
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
assert.isTrue(stack.isEmpty);
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
test('should handle large number of operations efficiently', () => {
|
|
@@ -181,18 +181,18 @@ describe('Stack test', () => {
|
|
|
181
181
|
|
|
182
182
|
expect(stack.size).toBe(n);
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
assert.isFalse(stack.isEmpty);
|
|
185
185
|
|
|
186
186
|
// Pop all elements and verify LIFO order
|
|
187
187
|
for (const i of range(asSafeInt(n - 1), -1, -1)) {
|
|
188
188
|
const result = stack.pop();
|
|
189
189
|
|
|
190
|
-
|
|
190
|
+
assert.isTrue(Optional.isSome(result));
|
|
191
191
|
|
|
192
192
|
expect(Optional.unwrap(result)).toBe(i);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
|
|
195
|
+
assert.isTrue(stack.isEmpty);
|
|
196
196
|
|
|
197
197
|
expect(stack.size).toBe(0);
|
|
198
198
|
});
|
|
@@ -237,7 +237,7 @@ describe('Stack test', () => {
|
|
|
237
237
|
|
|
238
238
|
expect(Optional.unwrap(stack.pop())).toBe('value');
|
|
239
239
|
|
|
240
|
-
|
|
240
|
+
assert.isTrue(stack.isEmpty);
|
|
241
241
|
});
|
|
242
242
|
|
|
243
243
|
test('should maintain performance characteristics', () => {
|
|
@@ -288,6 +288,6 @@ describe('Stack test', () => {
|
|
|
288
288
|
expect(Optional.unwrap(result)).toBe(i);
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
|
|
291
|
+
assert.isTrue(stack.isEmpty);
|
|
292
292
|
});
|
|
293
293
|
});
|
package/src/functional/match.mts
CHANGED
|
@@ -11,13 +11,13 @@ import { type Unwrap } from './types.mjs';
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* const optionalValue = Optional.some('data');
|
|
13
13
|
*
|
|
14
|
-
* assert(Optional.expectToBe(optionalValue, 'value expected') === 'data');
|
|
14
|
+
* assert.isTrue(Optional.expectToBe(optionalValue, 'value expected') === 'data');
|
|
15
15
|
*
|
|
16
16
|
* const expectValue = Optional.expectToBe<string>('missing optional');
|
|
17
17
|
*
|
|
18
18
|
* assert.throws(() => expectValue(Optional.none), /missing optional/u);
|
|
19
19
|
*
|
|
20
|
-
* assert(expectValue(Optional.some('present')) === 'present');
|
|
20
|
+
* assert.isTrue(expectValue(Optional.some('present')) === 'present');
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
23
|
* @template O The `UnknownOptional` type to unwrap.
|