semantic-typescript 0.0.4 → 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.
@@ -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
  }
@@ -148,7 +149,7 @@ export declare abstract class Collectable<E> {
148
149
  findLast(): Optional<E>;
149
150
  forEach(action: BiConsumer<E, bigint>): void;
150
151
  group<K>(classifier: Functional<E, K>): Map<K, Array<E>>;
151
- groupBy<K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Map<K, V>;
152
+ groupBy<K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Map<K, Array<V>>;
152
153
  join(): string;
153
154
  join(delimiter: string): string;
154
155
  join(prefix: string, delimiter: string, suffix: string): string;
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
- return new Semantic(generator);
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(...args) {
595
- let parameter = args[0];
596
- if (isBigint(parameter)) {
597
- let offset = parameter;
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(parameter)) {
605
- let translator = parameter;
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));
@@ -776,7 +786,9 @@ export class Collectable {
776
786
  }, (map, element) => {
777
787
  let key = keyExtractor(element);
778
788
  let value = valueExtractor(element);
779
- map.set(key, value);
789
+ let group = (validate(map.get(key)) ? map.get(key) : []);
790
+ group.push(value);
791
+ map.set(key, group);
780
792
  return map;
781
793
  }, (map) => {
782
794
  return map;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semantic-typescript",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",