semantic-typescript 0.0.5 → 0.0.6
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/semantic.d.ts +1 -0
- package/dist/semantic.js +20 -10
- package/package.json +1 -1
package/dist/semantic.d.ts
CHANGED
|
@@ -114,6 +114,7 @@ export declare class Semantic<E> {
|
|
|
114
114
|
toBigintStatistics(): Statistics<E, bigint>;
|
|
115
115
|
toUnoredered(): UnorderedCollectable<E>;
|
|
116
116
|
toWindow(): WindowCollectable<E>;
|
|
117
|
+
translate(offset: number): Semantic<E>;
|
|
117
118
|
translate(offset: bigint): Semantic<E>;
|
|
118
119
|
translate(translator: BiFunctional<E, bigint, bigint>): Semantic<E>;
|
|
119
120
|
}
|
package/dist/semantic.js
CHANGED
|
@@ -177,7 +177,7 @@ class Optional {
|
|
|
177
177
|
this.value = value;
|
|
178
178
|
}
|
|
179
179
|
filter(predicate) {
|
|
180
|
-
if (this.isPresent() && predicate(this.value)) {
|
|
180
|
+
if (this.isPresent() && isFunction(predicate) && predicate(this.value)) {
|
|
181
181
|
return new Optional(this.value);
|
|
182
182
|
}
|
|
183
183
|
return new Optional((void 0));
|
|
@@ -198,7 +198,7 @@ class Optional {
|
|
|
198
198
|
throw new TypeError("Default value is not valid");
|
|
199
199
|
}
|
|
200
200
|
ifPresent(action) {
|
|
201
|
-
if (this.isPresent()) {
|
|
201
|
+
if (this.isPresent() && isFunction(action)) {
|
|
202
202
|
action(this.value);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
@@ -209,7 +209,7 @@ class Optional {
|
|
|
209
209
|
return validate(this.value);
|
|
210
210
|
}
|
|
211
211
|
map(mapper) {
|
|
212
|
-
if (this.isPresent()) {
|
|
212
|
+
if (this.isPresent() && isFunction(mapper)) {
|
|
213
213
|
return new Optional(mapper(this.value));
|
|
214
214
|
}
|
|
215
215
|
return new Optional(null);
|
|
@@ -293,7 +293,10 @@ export let range = (start, end, step = (typeof start === 'bigint' ? 1n : 1)) =>
|
|
|
293
293
|
throw new TypeError("Invalid arguments.");
|
|
294
294
|
};
|
|
295
295
|
export function iterate(generator) {
|
|
296
|
-
|
|
296
|
+
if (isFunction(generator)) {
|
|
297
|
+
return new Semantic(generator);
|
|
298
|
+
}
|
|
299
|
+
throw new TypeError("Invalid arguments.");
|
|
297
300
|
}
|
|
298
301
|
export class Semantic {
|
|
299
302
|
generator;
|
|
@@ -591,18 +594,25 @@ export class Semantic {
|
|
|
591
594
|
toWindow() {
|
|
592
595
|
return new WindowCollectable(this.generator);
|
|
593
596
|
}
|
|
594
|
-
translate(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
597
|
+
translate(argument1) {
|
|
598
|
+
if (isNumber(argument1)) {
|
|
599
|
+
let offset = argument1;
|
|
600
|
+
return new Semantic((accept, interrupt) => {
|
|
601
|
+
this.generator((element, index) => {
|
|
602
|
+
accept(element, index + BigInt(offset));
|
|
603
|
+
}, interrupt);
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
else if (isBigint(argument1)) {
|
|
607
|
+
let offset = argument1;
|
|
598
608
|
return new Semantic((accept, interrupt) => {
|
|
599
609
|
this.generator((element, index) => {
|
|
600
610
|
accept(element, index + offset);
|
|
601
611
|
}, interrupt);
|
|
602
612
|
});
|
|
603
613
|
}
|
|
604
|
-
else if (isFunction(
|
|
605
|
-
let translator =
|
|
614
|
+
else if (isFunction(argument1)) {
|
|
615
|
+
let translator = argument1;
|
|
606
616
|
return new Semantic((accept, interrupt) => {
|
|
607
617
|
this.generator((element, index) => {
|
|
608
618
|
accept(element, index + translator(element, index));
|