scats 1.4.4 → 1.5.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.
@@ -42,7 +42,7 @@ export class ArrayBackedCollection extends ArrayIterable {
42
42
  return this.fromArray(this.items.concat([item]));
43
43
  }
44
44
  appendedAll(other) {
45
- return this.fromArray(this.items.concat(...other));
45
+ return this.fromArray(this.items.concat([...other]));
46
46
  }
47
47
  prepended(item) {
48
48
  return this.fromArray([item].concat(this.items));
package/dist/either.d.ts CHANGED
@@ -21,6 +21,7 @@ export declare abstract class Either<LEFT, RIGHT> implements Mappable<RIGHT> {
21
21
  contains(elem: RIGHT): boolean;
22
22
  forall(f: (right: RIGHT) => boolean): boolean;
23
23
  exists(p: (right: RIGHT) => boolean): boolean;
24
+ join<OTHERS extends Either<LEFT, any>[]>(...others: OTHERS): Either<LEFT, [RIGHT, ...Either.RightValues<OTHERS>]>;
24
25
  flatMap<RIGHT1>(f: (value: RIGHT) => Either<LEFT, RIGHT1>): Either<LEFT, RIGHT1>;
25
26
  flatMapPromise<RIGHT1>(f: (item: RIGHT) => Promise<Either<LEFT, RIGHT1>>): Promise<Either<LEFT, RIGHT1>>;
26
27
  map<RIGHT1>(f: (value: RIGHT) => RIGHT1): Either<LEFT, RIGHT1>;
@@ -46,6 +47,11 @@ export declare class Right<T> extends Either<any, T> {
46
47
  withLeft<LEFT>(): Either<LEFT, T>;
47
48
  }
48
49
  export declare namespace Either {
50
+ type RightValue<E> = E extends Either<any, infer RIGHT> ? RIGHT : never;
51
+ type RightValues<ES extends Either<any, any>[]> = {
52
+ [K in keyof ES]: RightValue<ES[K]>;
53
+ };
54
+ function join<LEFT, ES extends [Either<LEFT, any>, ...Either<LEFT, any>[]]>(...eithers: ES): Either<LEFT, RightValues<ES>>;
49
55
  class LeftProjection<A, B> {
50
56
  private readonly e;
51
57
  constructor(e: Either<A, B>);
package/dist/either.js CHANGED
@@ -2,6 +2,13 @@ import { none, some } from './option.js';
2
2
  import { Collection, Nil } from './collection.js';
3
3
  import { failure, success } from './try.js';
4
4
  import { toErrorConversion } from './util.js';
5
+ function joinEitherValues(values, eithers) {
6
+ if (eithers.length <= 0) {
7
+ return right(values);
8
+ }
9
+ const [current, ...rest] = eithers;
10
+ return current.flatMap(value => joinEitherValues([...values, value], rest));
11
+ }
5
12
  export class Either {
6
13
  get isRight() {
7
14
  return !this.isLeft;
@@ -70,6 +77,9 @@ export class Either {
70
77
  left: () => false
71
78
  });
72
79
  }
80
+ join(...others) {
81
+ return this.flatMap(value => joinEitherValues([value], others));
82
+ }
73
83
  flatMap(f) {
74
84
  return this.match({
75
85
  right: v => f(v),
@@ -158,6 +168,11 @@ export class Right extends Either {
158
168
  }
159
169
  }
160
170
  (function (Either) {
171
+ function join(...eithers) {
172
+ const [head, ...tail] = eithers;
173
+ return head.flatMap(value => joinEitherValues([value], tail));
174
+ }
175
+ Either.join = join;
161
176
  class LeftProjection {
162
177
  e;
163
178
  constructor(e) {
package/dist/index.cjs CHANGED
@@ -419,7 +419,7 @@ class ArrayBackedCollection extends ArrayIterable {
419
419
  return this.fromArray(this.items.concat([item]));
420
420
  }
421
421
  appendedAll(other) {
422
- return this.fromArray(this.items.concat(...other));
422
+ return this.fromArray(this.items.concat([...other]));
423
423
  }
424
424
  prepended(item) {
425
425
  return this.fromArray([item].concat(this.items));
@@ -1531,6 +1531,13 @@ function failure(x) {
1531
1531
  return new Failure(x);
1532
1532
  }
1533
1533
 
1534
+ function joinEitherValues(values, eithers) {
1535
+ if (eithers.length <= 0) {
1536
+ return right(values);
1537
+ }
1538
+ const [current, ...rest] = eithers;
1539
+ return current.flatMap(value => joinEitherValues([...values, value], rest));
1540
+ }
1534
1541
  class Either {
1535
1542
  get isRight() {
1536
1543
  return !this.isLeft;
@@ -1599,6 +1606,9 @@ class Either {
1599
1606
  left: () => false
1600
1607
  });
1601
1608
  }
1609
+ join(...others) {
1610
+ return this.flatMap(value => joinEitherValues([value], others));
1611
+ }
1602
1612
  flatMap(f) {
1603
1613
  return this.match({
1604
1614
  right: v => f(v),
@@ -1687,6 +1697,11 @@ class Right extends Either {
1687
1697
  }
1688
1698
  }
1689
1699
  (function (Either) {
1700
+ function join(...eithers) {
1701
+ const [head, ...tail] = eithers;
1702
+ return head.flatMap(value => joinEitherValues([value], tail));
1703
+ }
1704
+ Either.join = join;
1690
1705
  class LeftProjection {
1691
1706
  e;
1692
1707
  constructor(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scats",
3
- "version": "1.4.4",
3
+ "version": "1.5.0",
4
4
  "description": "Useful scala classes in typescript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",