scats 1.4.0-dev → 1.4.1-dev
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/abstract-map.d.ts +4 -4
- package/dist/abstract-map.js +12 -15
- package/dist/abstract-set.d.ts +2 -2
- package/dist/abstract-set.js +6 -9
- package/dist/array-iterable.d.ts +1 -1
- package/dist/array-iterable.js +22 -26
- package/dist/collection.d.ts +4 -4
- package/dist/collection.js +50 -71
- package/dist/either.d.ts +4 -4
- package/dist/either.js +31 -39
- package/dist/hashmap.d.ts +2 -2
- package/dist/hashmap.js +9 -12
- package/dist/hashset.d.ts +3 -3
- package/dist/hashset.js +6 -11
- package/dist/index.d.ts +8 -8
- package/dist/index.js +9 -13
- package/dist/mappable.js +1 -2
- package/dist/mutable/hashmap.d.ts +3 -3
- package/dist/mutable/hashmap.js +3 -8
- package/dist/mutable/hashset.d.ts +2 -2
- package/dist/mutable/hashset.js +3 -8
- package/dist/mutable.d.ts +3 -3
- package/dist/mutable.js +3 -9
- package/dist/option.d.ts +6 -6
- package/dist/option.js +34 -44
- package/dist/try.d.ts +3 -3
- package/dist/try.js +27 -37
- package/dist/util.d.ts +2 -2
- package/dist/util.js +41 -50
- package/package.json +1 -1
- package/.eslintrc.cjs +0 -44
- package/coverage/clover.xml +0 -937
- package/coverage/coverage-final.json +0 -15
- package/coverage/lcov-report/array-iterable.ts.html +0 -1709
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/collection.ts.html +0 -1475
- package/coverage/lcov-report/either.ts.html +0 -1934
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/hashmap.ts.html +0 -527
- package/coverage/lcov-report/hashset.ts.html +0 -392
- package/coverage/lcov-report/index.html +0 -126
- package/coverage/lcov-report/index.ts.html +0 -101
- package/coverage/lcov-report/option.ts.html +0 -758
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov-report/src/abstract-map.ts.html +0 -317
- package/coverage/lcov-report/src/abstract-set.ts.html +0 -200
- package/coverage/lcov-report/src/array-iterable.ts.html +0 -1751
- package/coverage/lcov-report/src/collection.ts.html +0 -1778
- package/coverage/lcov-report/src/either.ts.html +0 -1934
- package/coverage/lcov-report/src/hashmap.ts.html +0 -428
- package/coverage/lcov-report/src/hashset.ts.html +0 -482
- package/coverage/lcov-report/src/index.html +0 -276
- package/coverage/lcov-report/src/index.ts.html +0 -110
- package/coverage/lcov-report/src/mutable/hashmap.ts.html +0 -821
- package/coverage/lcov-report/src/mutable/hashset.ts.html +0 -611
- package/coverage/lcov-report/src/mutable/index.html +0 -126
- package/coverage/lcov-report/src/mutable.ts.html +0 -89
- package/coverage/lcov-report/src/option.ts.html +0 -758
- package/coverage/lcov-report/src/try.ts.html +0 -923
- package/coverage/lcov-report/src/util.ts.html +0 -518
- package/coverage/lcov-report/try.ts.html +0 -923
- package/coverage/lcov-report/util.ts.html +0 -518
- package/coverage/lcov.info +0 -2223
- package/jest.config.js +0 -32
- package/src/abstract-map.ts +0 -79
- package/src/abstract-set.ts +0 -40
- package/src/array-iterable.ts +0 -557
- package/src/collection.ts +0 -619
- package/src/either.ts +0 -618
- package/src/hashmap.ts +0 -116
- package/src/hashset.ts +0 -134
- package/src/index.ts +0 -10
- package/src/mappable.ts +0 -8
- package/src/mutable/hashmap.ts +0 -247
- package/src/mutable/hashset.ts +0 -177
- package/src/mutable.ts +0 -3
- package/src/option.ts +0 -226
- package/src/try.ts +0 -281
- package/src/util.ts +0 -146
package/dist/hashmap.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { mutable } from './index.js';
|
|
2
|
+
import { AbstractMap } from './abstract-map.js';
|
|
3
|
+
export class HashMap extends AbstractMap {
|
|
4
|
+
map;
|
|
5
|
+
fromArray(array) {
|
|
6
|
+
return HashMap.of(...array);
|
|
7
|
+
}
|
|
7
8
|
constructor(map) {
|
|
8
9
|
super(map);
|
|
9
10
|
this.map = map;
|
|
10
11
|
}
|
|
11
|
-
fromArray(array) {
|
|
12
|
-
return HashMap.of(...array);
|
|
13
|
-
}
|
|
14
12
|
static of(...values) {
|
|
15
13
|
return new HashMap(new Map(values));
|
|
16
14
|
}
|
|
17
15
|
static from(values) {
|
|
18
16
|
return HashMap.of(...Array.from(values));
|
|
19
17
|
}
|
|
18
|
+
static empty = new HashMap(new Map());
|
|
20
19
|
appendedAll(map) {
|
|
21
20
|
return this.concat(map);
|
|
22
21
|
}
|
|
@@ -66,8 +65,6 @@ class HashMap extends abstract_map_1.AbstractMap {
|
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
67
|
get toMutable() {
|
|
69
|
-
return
|
|
68
|
+
return mutable.HashMap.of(...Array.from(this.map.entries()));
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
|
-
exports.HashMap = HashMap;
|
|
73
|
-
HashMap.empty = new HashMap(new Map());
|
package/dist/hashset.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HashMap } from './hashmap';
|
|
2
|
-
import { AbstractSet } from './abstract-set';
|
|
3
|
-
import * as mutable from './mutable/hashset';
|
|
1
|
+
import { HashMap } from './hashmap.js';
|
|
2
|
+
import { AbstractSet } from './abstract-set.js';
|
|
3
|
+
import * as mutable from './mutable/hashset.js';
|
|
4
4
|
export declare class HashSet<T> extends AbstractSet<T, HashSet<T>> {
|
|
5
5
|
protected constructor(items: Set<T>);
|
|
6
6
|
static empty: HashSet<any>;
|
package/dist/hashset.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const hashmap_1 = require("./hashmap");
|
|
6
|
-
const abstract_set_1 = require("./abstract-set");
|
|
7
|
-
const mutable = (0, tslib_1.__importStar)(require("./mutable/hashset"));
|
|
8
|
-
class HashSet extends abstract_set_1.AbstractSet {
|
|
1
|
+
import { HashMap } from './hashmap.js';
|
|
2
|
+
import { AbstractSet } from './abstract-set.js';
|
|
3
|
+
import * as mutable from './mutable/hashset.js';
|
|
4
|
+
export class HashSet extends AbstractSet {
|
|
9
5
|
constructor(items) {
|
|
10
6
|
super(items);
|
|
11
7
|
}
|
|
8
|
+
static empty = new HashSet(new Set());
|
|
12
9
|
static of(...items) {
|
|
13
10
|
return new HashSet(new Set(items));
|
|
14
11
|
}
|
|
@@ -19,7 +16,7 @@ class HashSet extends abstract_set_1.AbstractSet {
|
|
|
19
16
|
return HashSet.of(...array);
|
|
20
17
|
}
|
|
21
18
|
toMap(mapper) {
|
|
22
|
-
return
|
|
19
|
+
return HashMap.of(...this.map(mapper).toArray);
|
|
23
20
|
}
|
|
24
21
|
map(f) {
|
|
25
22
|
return HashSet.of(...Array.from(this.items).map(i => f(i)));
|
|
@@ -62,5 +59,3 @@ class HashSet extends abstract_set_1.AbstractSet {
|
|
|
62
59
|
return mutable.HashSet.of(...this.items);
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
exports.HashSet = HashSet;
|
|
66
|
-
HashSet.empty = new HashSet(new Set());
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './collection';
|
|
2
|
-
export * from './either';
|
|
3
|
-
export * from './hashmap';
|
|
4
|
-
export * from './hashset';
|
|
5
|
-
export * from './option';
|
|
6
|
-
export * from './try';
|
|
7
|
-
export * from './util';
|
|
8
|
-
import * as mutable from './mutable';
|
|
1
|
+
export * from './collection.js';
|
|
2
|
+
export * from './either.js';
|
|
3
|
+
export * from './hashmap.js';
|
|
4
|
+
export * from './hashset.js';
|
|
5
|
+
export * from './option.js';
|
|
6
|
+
export * from './try.js';
|
|
7
|
+
export * from './util.js';
|
|
8
|
+
import * as mutable from './mutable.js';
|
|
9
9
|
export { mutable };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
(0, tslib_1.__exportStar)(require("./try"), exports);
|
|
11
|
-
(0, tslib_1.__exportStar)(require("./util"), exports);
|
|
12
|
-
const mutable = (0, tslib_1.__importStar)(require("./mutable"));
|
|
13
|
-
exports.mutable = mutable;
|
|
1
|
+
export * from './collection.js';
|
|
2
|
+
export * from './either.js';
|
|
3
|
+
export * from './hashmap.js';
|
|
4
|
+
export * from './hashset.js';
|
|
5
|
+
export * from './option.js';
|
|
6
|
+
export * from './try.js';
|
|
7
|
+
export * from './util.js';
|
|
8
|
+
import * as mutable from './mutable.js';
|
|
9
|
+
export { mutable };
|
package/dist/mappable.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Option } from '../option';
|
|
2
|
-
import { AbstractMap, Tuple2 } from '../abstract-map';
|
|
3
|
-
import * as immutable from '../hashmap';
|
|
1
|
+
import { Option } from '../option.js';
|
|
2
|
+
import { AbstractMap, Tuple2 } from '../abstract-map.js';
|
|
3
|
+
import * as immutable from '../hashmap.js';
|
|
4
4
|
export declare class HashMap<K, V> extends AbstractMap<K, V, HashMap<K, V>> {
|
|
5
5
|
constructor(map?: Map<K, V>);
|
|
6
6
|
protected fromArray(array: Tuple2<K, V>[]): HashMap<K, V>;
|
package/dist/mutable/hashmap.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const abstract_map_1 = require("../abstract-map");
|
|
6
|
-
const immutable = (0, tslib_1.__importStar)(require("../hashmap"));
|
|
7
|
-
class HashMap extends abstract_map_1.AbstractMap {
|
|
1
|
+
import { AbstractMap } from '../abstract-map.js';
|
|
2
|
+
import * as immutable from '../hashmap.js';
|
|
3
|
+
export class HashMap extends AbstractMap {
|
|
8
4
|
constructor(map = new Map()) {
|
|
9
5
|
super(map);
|
|
10
6
|
}
|
|
@@ -115,4 +111,3 @@ class HashMap extends abstract_map_1.AbstractMap {
|
|
|
115
111
|
return immutable.HashMap.of(...this.map.entries());
|
|
116
112
|
}
|
|
117
113
|
}
|
|
118
|
-
exports.HashMap = HashMap;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractSet } from '../abstract-set';
|
|
2
|
-
import * as immutable from '../hashset';
|
|
1
|
+
import { AbstractSet } from '../abstract-set.js';
|
|
2
|
+
import * as immutable from '../hashset.js';
|
|
3
3
|
export declare class HashSet<T> extends AbstractSet<T, HashSet<T>> {
|
|
4
4
|
constructor(items?: Set<T>);
|
|
5
5
|
static of<T>(...items: T[]): HashSet<T>;
|
package/dist/mutable/hashset.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const abstract_set_1 = require("../abstract-set");
|
|
6
|
-
const immutable = (0, tslib_1.__importStar)(require("../hashset"));
|
|
7
|
-
class HashSet extends abstract_set_1.AbstractSet {
|
|
1
|
+
import { AbstractSet } from '../abstract-set.js';
|
|
2
|
+
import * as immutable from '../hashset.js';
|
|
3
|
+
export class HashSet extends AbstractSet {
|
|
8
4
|
constructor(items = new Set()) {
|
|
9
5
|
super(items);
|
|
10
6
|
}
|
|
@@ -85,4 +81,3 @@ class HashSet extends abstract_set_1.AbstractSet {
|
|
|
85
81
|
return immutable.HashSet.of(...this.items);
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
|
-
exports.HashSet = HashSet;
|
package/dist/mutable.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { ArrayBuffer } from './collection';
|
|
2
|
-
export { HashMap } from './mutable/hashmap';
|
|
3
|
-
export { HashSet } from './mutable/hashset';
|
|
1
|
+
export { ArrayBuffer } from './collection.js';
|
|
2
|
+
export { HashMap } from './mutable/hashmap.js';
|
|
3
|
+
export { HashSet } from './mutable/hashset.js';
|
package/dist/mutable.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var collection_1 = require("./collection");
|
|
5
|
-
Object.defineProperty(exports, "ArrayBuffer", { enumerable: true, get: function () { return collection_1.ArrayBuffer; } });
|
|
6
|
-
var hashmap_1 = require("./mutable/hashmap");
|
|
7
|
-
Object.defineProperty(exports, "HashMap", { enumerable: true, get: function () { return hashmap_1.HashMap; } });
|
|
8
|
-
var hashset_1 = require("./mutable/hashset");
|
|
9
|
-
Object.defineProperty(exports, "HashSet", { enumerable: true, get: function () { return hashset_1.HashSet; } });
|
|
1
|
+
export { ArrayBuffer } from './collection.js';
|
|
2
|
+
export { HashMap } from './mutable/hashmap.js';
|
|
3
|
+
export { HashSet } from './mutable/hashset.js';
|
package/dist/option.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Collection } from './collection';
|
|
2
|
-
import { Either } from './either';
|
|
3
|
-
import { ArrayIterable } from './array-iterable';
|
|
4
|
-
import { HashSet } from './hashset';
|
|
5
|
-
import { HashMap } from './hashmap';
|
|
6
|
-
import { Mappable } from './mappable';
|
|
1
|
+
import { Collection } from './collection.js';
|
|
2
|
+
import { Either } from './either.js';
|
|
3
|
+
import { ArrayIterable } from './array-iterable.js';
|
|
4
|
+
import { HashSet } from './hashset.js';
|
|
5
|
+
import { HashMap } from './hashmap.js';
|
|
6
|
+
import { Mappable } from './mappable.js';
|
|
7
7
|
export interface OptionMatch<A, T> {
|
|
8
8
|
some: (value: A) => T;
|
|
9
9
|
none: () => T;
|
package/dist/option.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const array_iterable_1 = require("./array-iterable");
|
|
8
|
-
const hashset_1 = require("./hashset");
|
|
9
|
-
const hashmap_1 = require("./hashmap");
|
|
10
|
-
class Option extends array_iterable_1.ArrayIterable {
|
|
1
|
+
import { Collection } from './collection.js';
|
|
2
|
+
import { Left, left, Right, right } from './either.js';
|
|
3
|
+
import { ArrayIterable } from './array-iterable.js';
|
|
4
|
+
import { HashSet } from './hashset.js';
|
|
5
|
+
import { HashMap } from './hashmap.js';
|
|
6
|
+
export class Option extends ArrayIterable {
|
|
11
7
|
static when(cond) {
|
|
12
8
|
return a => {
|
|
13
9
|
if (cond) {
|
|
14
10
|
return some(a());
|
|
15
11
|
}
|
|
16
12
|
else {
|
|
17
|
-
return
|
|
13
|
+
return none;
|
|
18
14
|
}
|
|
19
15
|
};
|
|
20
16
|
}
|
|
@@ -23,7 +19,7 @@ class Option extends array_iterable_1.ArrayIterable {
|
|
|
23
19
|
}
|
|
24
20
|
fromArray(array) {
|
|
25
21
|
if (array.length <= 0) {
|
|
26
|
-
return
|
|
22
|
+
return none;
|
|
27
23
|
}
|
|
28
24
|
else {
|
|
29
25
|
return some(array[0]);
|
|
@@ -39,39 +35,37 @@ class Option extends array_iterable_1.ArrayIterable {
|
|
|
39
35
|
}
|
|
40
36
|
filter(p) {
|
|
41
37
|
if (this.isEmpty) {
|
|
42
|
-
return
|
|
38
|
+
return none;
|
|
43
39
|
}
|
|
44
40
|
else {
|
|
45
|
-
return p(this.get) ? this :
|
|
41
|
+
return p(this.get) ? this : none;
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
44
|
filterNot(p) {
|
|
49
45
|
if (this.isEmpty) {
|
|
50
|
-
return
|
|
46
|
+
return none;
|
|
51
47
|
}
|
|
52
48
|
else {
|
|
53
|
-
return p(this.get) ?
|
|
49
|
+
return p(this.get) ? none : this;
|
|
54
50
|
}
|
|
55
51
|
}
|
|
56
52
|
map(f) {
|
|
57
|
-
return this.isEmpty ?
|
|
53
|
+
return this.isEmpty ? none : some(f(this.get));
|
|
58
54
|
}
|
|
59
55
|
flatMap(p) {
|
|
60
|
-
return this.isEmpty ?
|
|
56
|
+
return this.isEmpty ? none : p(this.get);
|
|
61
57
|
}
|
|
62
|
-
mapPromise(f) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
});
|
|
58
|
+
async mapPromise(f) {
|
|
59
|
+
if (this.isEmpty) {
|
|
60
|
+
return Promise.resolve(none);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return option(await f(this.get));
|
|
64
|
+
}
|
|
71
65
|
}
|
|
72
66
|
flatMapPromise(f) {
|
|
73
67
|
if (this.isEmpty) {
|
|
74
|
-
return Promise.resolve(
|
|
68
|
+
return Promise.resolve(none);
|
|
75
69
|
}
|
|
76
70
|
else {
|
|
77
71
|
return f(this.get);
|
|
@@ -126,29 +120,29 @@ class Option extends array_iterable_1.ArrayIterable {
|
|
|
126
120
|
return this.isEmpty ? undefined : this.get;
|
|
127
121
|
}
|
|
128
122
|
get toCollection() {
|
|
129
|
-
return this.isEmpty ?
|
|
123
|
+
return this.isEmpty ? Collection.empty : Collection.of(this.get);
|
|
130
124
|
}
|
|
131
125
|
toRight(left) {
|
|
132
|
-
return this.isEmpty ? new
|
|
126
|
+
return this.isEmpty ? new Left(left()) : right(this.get);
|
|
133
127
|
}
|
|
134
128
|
toLeft(right) {
|
|
135
|
-
return this.isEmpty ? new
|
|
129
|
+
return this.isEmpty ? new Right(right()) : left(this.get);
|
|
136
130
|
}
|
|
137
131
|
get toArray() {
|
|
138
132
|
return this.isEmpty ? [] : [this.get];
|
|
139
133
|
}
|
|
140
134
|
get toSet() {
|
|
141
|
-
return this.isEmpty ?
|
|
135
|
+
return this.isEmpty ? HashSet.empty : HashSet.of(this.get);
|
|
142
136
|
}
|
|
143
137
|
match(matcher) {
|
|
144
138
|
return this.isEmpty ? matcher.none() : matcher.some(this.get);
|
|
145
139
|
}
|
|
146
140
|
toMap(mapper) {
|
|
147
|
-
return this.isEmpty ?
|
|
141
|
+
return this.isEmpty ? HashMap.empty : HashMap.of(...this.map(mapper).toArray);
|
|
148
142
|
}
|
|
149
143
|
}
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
export class Some extends Option {
|
|
145
|
+
value;
|
|
152
146
|
constructor(value) {
|
|
153
147
|
super();
|
|
154
148
|
this.value = value;
|
|
@@ -160,8 +154,7 @@ class Some extends Option {
|
|
|
160
154
|
return false;
|
|
161
155
|
}
|
|
162
156
|
}
|
|
163
|
-
|
|
164
|
-
class None extends Option {
|
|
157
|
+
export class None extends Option {
|
|
165
158
|
get get() {
|
|
166
159
|
throw new Error('No such element.');
|
|
167
160
|
}
|
|
@@ -169,13 +162,10 @@ class None extends Option {
|
|
|
169
162
|
return true;
|
|
170
163
|
}
|
|
171
164
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return value === null || typeof value === 'undefined' ? exports.none : some(value);
|
|
165
|
+
export function option(value) {
|
|
166
|
+
return value === null || typeof value === 'undefined' ? none : some(value);
|
|
175
167
|
}
|
|
176
|
-
|
|
177
|
-
function some(value) {
|
|
168
|
+
export function some(value) {
|
|
178
169
|
return new Some(value);
|
|
179
170
|
}
|
|
180
|
-
|
|
181
|
-
exports.none = new None();
|
|
171
|
+
export const none = new None();
|
package/dist/try.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Option } from './option';
|
|
2
|
-
import { Either } from './either';
|
|
3
|
-
import { Mappable } from './mappable';
|
|
1
|
+
import { Option } from './option.js';
|
|
2
|
+
import { Either } from './either.js';
|
|
3
|
+
import { Mappable } from './mappable.js';
|
|
4
4
|
export interface TryMatch<T, R> {
|
|
5
5
|
success: (result: T) => R;
|
|
6
6
|
failure: (error: Error) => R;
|
package/dist/try.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
mapPromise(f) {
|
|
10
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
11
|
-
return this.match({
|
|
12
|
-
success: r => Try.promise(() => f(r)),
|
|
13
|
-
failure: () => Promise.resolve(this)
|
|
14
|
-
});
|
|
1
|
+
import { none, some } from './option.js';
|
|
2
|
+
import { left, right } from './either.js';
|
|
3
|
+
import { identity } from './util.js';
|
|
4
|
+
export class TryLike {
|
|
5
|
+
async mapPromise(f) {
|
|
6
|
+
return this.match({
|
|
7
|
+
success: r => Try.promise(() => f(r)),
|
|
8
|
+
failure: () => Promise.resolve(this)
|
|
15
9
|
});
|
|
16
10
|
}
|
|
17
11
|
flatMapPromise(f) {
|
|
@@ -41,24 +35,24 @@ class TryLike {
|
|
|
41
35
|
}
|
|
42
36
|
toEitherWithLeft(f) {
|
|
43
37
|
return this.match({
|
|
44
|
-
success: r =>
|
|
45
|
-
failure: e =>
|
|
38
|
+
success: r => right(r),
|
|
39
|
+
failure: e => left(f(e))
|
|
46
40
|
});
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
export class Success extends TryLike {
|
|
44
|
+
result;
|
|
45
|
+
isSuccess = true;
|
|
46
|
+
isFailure = false;
|
|
51
47
|
constructor(result) {
|
|
52
48
|
super();
|
|
53
49
|
this.result = result;
|
|
54
|
-
this.isSuccess = true;
|
|
55
|
-
this.isFailure = false;
|
|
56
50
|
}
|
|
57
51
|
get toOption() {
|
|
58
|
-
return
|
|
52
|
+
return some(this.result);
|
|
59
53
|
}
|
|
60
54
|
get toEither() {
|
|
61
|
-
return
|
|
55
|
+
return right(this.result);
|
|
62
56
|
}
|
|
63
57
|
map(f) {
|
|
64
58
|
return success(f(this.result));
|
|
@@ -120,19 +114,19 @@ class Success extends TryLike {
|
|
|
120
114
|
return this.flatMap(s);
|
|
121
115
|
}
|
|
122
116
|
}
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
export class Failure extends TryLike {
|
|
118
|
+
error;
|
|
119
|
+
isSuccess = false;
|
|
120
|
+
isFailure = true;
|
|
125
121
|
constructor(error) {
|
|
126
122
|
super();
|
|
127
123
|
this.error = error;
|
|
128
|
-
this.isSuccess = false;
|
|
129
|
-
this.isFailure = true;
|
|
130
124
|
}
|
|
131
125
|
get toOption() {
|
|
132
|
-
return
|
|
126
|
+
return none;
|
|
133
127
|
}
|
|
134
128
|
get toEither() {
|
|
135
|
-
return
|
|
129
|
+
return left(this.error);
|
|
136
130
|
}
|
|
137
131
|
map(_) {
|
|
138
132
|
return this;
|
|
@@ -178,7 +172,7 @@ class Failure extends TryLike {
|
|
|
178
172
|
}
|
|
179
173
|
}
|
|
180
174
|
recoverWith(f) {
|
|
181
|
-
return this.transform(
|
|
175
|
+
return this.transform(identity, f);
|
|
182
176
|
}
|
|
183
177
|
transform(s, f) {
|
|
184
178
|
try {
|
|
@@ -189,8 +183,7 @@ class Failure extends TryLike {
|
|
|
189
183
|
}
|
|
190
184
|
}
|
|
191
185
|
}
|
|
192
|
-
|
|
193
|
-
function Try(block) {
|
|
186
|
+
export function Try(block) {
|
|
194
187
|
try {
|
|
195
188
|
return new Success(block());
|
|
196
189
|
}
|
|
@@ -198,7 +191,6 @@ function Try(block) {
|
|
|
198
191
|
return new Failure(e);
|
|
199
192
|
}
|
|
200
193
|
}
|
|
201
|
-
exports.Try = Try;
|
|
202
194
|
(function (Try) {
|
|
203
195
|
function promise(block) {
|
|
204
196
|
try {
|
|
@@ -211,12 +203,10 @@ exports.Try = Try;
|
|
|
211
203
|
}
|
|
212
204
|
}
|
|
213
205
|
Try.promise = promise;
|
|
214
|
-
})(Try
|
|
215
|
-
function success(x) {
|
|
206
|
+
})(Try || (Try = {}));
|
|
207
|
+
export function success(x) {
|
|
216
208
|
return new Success(x);
|
|
217
209
|
}
|
|
218
|
-
|
|
219
|
-
function failure(x) {
|
|
210
|
+
export function failure(x) {
|
|
220
211
|
return new Failure(x);
|
|
221
212
|
}
|
|
222
|
-
exports.failure = failure;
|
package/dist/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Option } from './option';
|
|
2
|
-
import { Mappable } from './mappable';
|
|
1
|
+
import { Option } from './option.js';
|
|
2
|
+
import { Mappable } from './mappable.js';
|
|
3
3
|
export declare function identity<T>(x: T): T;
|
|
4
4
|
export declare function toErrorConversion(x: unknown): Error;
|
|
5
5
|
export declare type StepFunction<R> = (state: any) => R;
|