@lsby/ts-fp-data 0.0.2
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/cjs/either.cjs +104 -0
- package/dist/cjs/either.d.cts +39 -0
- package/dist/cjs/index.cjs +187 -0
- package/dist/cjs/index.d.cts +3 -0
- package/dist/cjs/maybe.cjs +85 -0
- package/dist/cjs/maybe.d.cts +30 -0
- package/dist/cjs/task.cjs +46 -0
- package/dist/cjs/task.d.cts +10 -0
- package/dist/esm/chunk-LDWARHRU.js +59 -0
- package/dist/esm/chunk-MUKICLFD.js +22 -0
- package/dist/esm/chunk-WNXSHYAM.js +78 -0
- package/dist/esm/either.d.ts +39 -0
- package/dist/esm/either.js +10 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/maybe.d.ts +30 -0
- package/dist/esm/maybe.js +10 -0
- package/dist/esm/task.d.ts +10 -0
- package/dist/esm/task.js +6 -0
- package/package.json +41 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/either.ts
|
|
21
|
+
var either_exports = {};
|
|
22
|
+
__export(either_exports, {
|
|
23
|
+
Either: () => Either,
|
|
24
|
+
Left: () => Left,
|
|
25
|
+
Right: () => Right
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(either_exports);
|
|
28
|
+
var Either = class {
|
|
29
|
+
static pure(a) {
|
|
30
|
+
return new Right(a);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var Left = class _Left extends Either {
|
|
34
|
+
constructor(\u503C) {
|
|
35
|
+
super();
|
|
36
|
+
this.\u503C = \u503C;
|
|
37
|
+
}
|
|
38
|
+
map(_f) {
|
|
39
|
+
return new _Left(this.\u503C);
|
|
40
|
+
}
|
|
41
|
+
mapLeft(f) {
|
|
42
|
+
return new _Left(f(this.\u503C));
|
|
43
|
+
}
|
|
44
|
+
bind(_f) {
|
|
45
|
+
return new _Left(this.\u503C);
|
|
46
|
+
}
|
|
47
|
+
isLeft() {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
isRight() {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
getLeft() {
|
|
54
|
+
return this.\u503C;
|
|
55
|
+
}
|
|
56
|
+
getValue() {
|
|
57
|
+
return this.\u503C;
|
|
58
|
+
}
|
|
59
|
+
assertLeft() {
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
assertRight() {
|
|
63
|
+
throw new Error("\u65AD\u8A00\u5931\u8D25");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var Right = class _Right extends Either {
|
|
67
|
+
constructor(\u503C) {
|
|
68
|
+
super();
|
|
69
|
+
this.\u503C = \u503C;
|
|
70
|
+
}
|
|
71
|
+
map(f) {
|
|
72
|
+
return new _Right(f(this.\u503C));
|
|
73
|
+
}
|
|
74
|
+
mapLeft(_f) {
|
|
75
|
+
return new _Right(this.\u503C);
|
|
76
|
+
}
|
|
77
|
+
bind(f) {
|
|
78
|
+
return f(this.\u503C);
|
|
79
|
+
}
|
|
80
|
+
isLeft() {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
isRight() {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
getRight() {
|
|
87
|
+
return this.\u503C;
|
|
88
|
+
}
|
|
89
|
+
getValue() {
|
|
90
|
+
return this.\u503C;
|
|
91
|
+
}
|
|
92
|
+
assertLeft() {
|
|
93
|
+
throw new Error("\u65AD\u8A00\u5931\u8D25");
|
|
94
|
+
}
|
|
95
|
+
assertRight() {
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
Either,
|
|
102
|
+
Left,
|
|
103
|
+
Right
|
|
104
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
declare abstract class Either<L, R> {
|
|
2
|
+
static pure<L, R>(a: R): Either<L, R>;
|
|
3
|
+
abstract map<B>(_f: (a: R) => B): Either<L, B>;
|
|
4
|
+
abstract mapLeft<B>(f: (a: L) => B): Either<B, R>;
|
|
5
|
+
abstract bind<B>(_f: (a: R) => Either<L, B>): Either<L, B>;
|
|
6
|
+
abstract isLeft(): this is Left<L, R>;
|
|
7
|
+
abstract isRight(): this is Right<L, R>;
|
|
8
|
+
abstract getValue(): L | R;
|
|
9
|
+
abstract assertLeft(): Left<L, R>;
|
|
10
|
+
abstract assertRight(): Right<L, R>;
|
|
11
|
+
}
|
|
12
|
+
declare class Left<L, R> extends Either<L, R> {
|
|
13
|
+
private 值;
|
|
14
|
+
constructor(值: L);
|
|
15
|
+
map<B>(_f: (a: R) => B): Either<L, B>;
|
|
16
|
+
mapLeft<B>(f: (a: L) => B): Either<B, R>;
|
|
17
|
+
bind<B>(_f: (a: R) => Either<L, B>): Either<L, B>;
|
|
18
|
+
isLeft(): this is Left<L, R>;
|
|
19
|
+
isRight(): this is Right<L, R>;
|
|
20
|
+
getLeft(): L;
|
|
21
|
+
getValue(): L | R;
|
|
22
|
+
assertLeft(): Left<L, R>;
|
|
23
|
+
assertRight(): Right<L, R>;
|
|
24
|
+
}
|
|
25
|
+
declare class Right<L, R> extends Either<L, R> {
|
|
26
|
+
private 值;
|
|
27
|
+
constructor(值: R);
|
|
28
|
+
map<B>(f: (a: R) => B): Either<L, B>;
|
|
29
|
+
mapLeft<B>(_f: (a: L) => B): Either<B, R>;
|
|
30
|
+
bind<B>(f: (a: R) => Either<L, B>): Either<L, B>;
|
|
31
|
+
isLeft(): this is Left<L, R>;
|
|
32
|
+
isRight(): this is Right<L, R>;
|
|
33
|
+
getRight(): R;
|
|
34
|
+
getValue(): L | R;
|
|
35
|
+
assertLeft(): Left<L, R>;
|
|
36
|
+
assertRight(): Right<L, R>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { Either, Left, Right };
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Either: () => Either,
|
|
24
|
+
Just: () => Just,
|
|
25
|
+
Left: () => Left,
|
|
26
|
+
Maybe: () => Maybe,
|
|
27
|
+
Nothing: () => Nothing,
|
|
28
|
+
Right: () => Right,
|
|
29
|
+
Task: () => Task
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
|
|
33
|
+
// src/task.ts
|
|
34
|
+
var Task = class _Task {
|
|
35
|
+
constructor(f) {
|
|
36
|
+
this.f = f;
|
|
37
|
+
}
|
|
38
|
+
static pure(a) {
|
|
39
|
+
return new _Task(async () => a);
|
|
40
|
+
}
|
|
41
|
+
map(f) {
|
|
42
|
+
return new _Task(async () => f(await this.f()));
|
|
43
|
+
}
|
|
44
|
+
bind(f) {
|
|
45
|
+
return new _Task(async () => f(await this.f()).run());
|
|
46
|
+
}
|
|
47
|
+
run() {
|
|
48
|
+
return this.f();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/maybe.ts
|
|
53
|
+
var Maybe = class {
|
|
54
|
+
static pure(a) {
|
|
55
|
+
return new Just(a);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var Just = class _Just extends Maybe {
|
|
59
|
+
constructor(\u503C) {
|
|
60
|
+
super();
|
|
61
|
+
this.\u503C = \u503C;
|
|
62
|
+
}
|
|
63
|
+
match(onJust, _onNothing) {
|
|
64
|
+
return onJust(this.\u503C);
|
|
65
|
+
}
|
|
66
|
+
map(f) {
|
|
67
|
+
return new _Just(f(this.\u503C));
|
|
68
|
+
}
|
|
69
|
+
bind(f) {
|
|
70
|
+
return f(this.\u503C);
|
|
71
|
+
}
|
|
72
|
+
isJust() {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
isNothing() {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
getJust() {
|
|
79
|
+
return this.\u503C;
|
|
80
|
+
}
|
|
81
|
+
getJustOrNull() {
|
|
82
|
+
return this.\u503C;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var Nothing = class _Nothing extends Maybe {
|
|
86
|
+
match(_onJust, onNothing) {
|
|
87
|
+
return onNothing();
|
|
88
|
+
}
|
|
89
|
+
map(_f) {
|
|
90
|
+
return new _Nothing();
|
|
91
|
+
}
|
|
92
|
+
bind(_f) {
|
|
93
|
+
return new _Nothing();
|
|
94
|
+
}
|
|
95
|
+
isJust() {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
isNothing() {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
getJustOrNull() {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/either.ts
|
|
107
|
+
var Either = class {
|
|
108
|
+
static pure(a) {
|
|
109
|
+
return new Right(a);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var Left = class _Left extends Either {
|
|
113
|
+
constructor(\u503C) {
|
|
114
|
+
super();
|
|
115
|
+
this.\u503C = \u503C;
|
|
116
|
+
}
|
|
117
|
+
map(_f) {
|
|
118
|
+
return new _Left(this.\u503C);
|
|
119
|
+
}
|
|
120
|
+
mapLeft(f) {
|
|
121
|
+
return new _Left(f(this.\u503C));
|
|
122
|
+
}
|
|
123
|
+
bind(_f) {
|
|
124
|
+
return new _Left(this.\u503C);
|
|
125
|
+
}
|
|
126
|
+
isLeft() {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
isRight() {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
getLeft() {
|
|
133
|
+
return this.\u503C;
|
|
134
|
+
}
|
|
135
|
+
getValue() {
|
|
136
|
+
return this.\u503C;
|
|
137
|
+
}
|
|
138
|
+
assertLeft() {
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
assertRight() {
|
|
142
|
+
throw new Error("\u65AD\u8A00\u5931\u8D25");
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var Right = class _Right extends Either {
|
|
146
|
+
constructor(\u503C) {
|
|
147
|
+
super();
|
|
148
|
+
this.\u503C = \u503C;
|
|
149
|
+
}
|
|
150
|
+
map(f) {
|
|
151
|
+
return new _Right(f(this.\u503C));
|
|
152
|
+
}
|
|
153
|
+
mapLeft(_f) {
|
|
154
|
+
return new _Right(this.\u503C);
|
|
155
|
+
}
|
|
156
|
+
bind(f) {
|
|
157
|
+
return f(this.\u503C);
|
|
158
|
+
}
|
|
159
|
+
isLeft() {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
isRight() {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
getRight() {
|
|
166
|
+
return this.\u503C;
|
|
167
|
+
}
|
|
168
|
+
getValue() {
|
|
169
|
+
return this.\u503C;
|
|
170
|
+
}
|
|
171
|
+
assertLeft() {
|
|
172
|
+
throw new Error("\u65AD\u8A00\u5931\u8D25");
|
|
173
|
+
}
|
|
174
|
+
assertRight() {
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
179
|
+
0 && (module.exports = {
|
|
180
|
+
Either,
|
|
181
|
+
Just,
|
|
182
|
+
Left,
|
|
183
|
+
Maybe,
|
|
184
|
+
Nothing,
|
|
185
|
+
Right,
|
|
186
|
+
Task
|
|
187
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/maybe.ts
|
|
21
|
+
var maybe_exports = {};
|
|
22
|
+
__export(maybe_exports, {
|
|
23
|
+
Just: () => Just,
|
|
24
|
+
Maybe: () => Maybe,
|
|
25
|
+
Nothing: () => Nothing
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(maybe_exports);
|
|
28
|
+
var Maybe = class {
|
|
29
|
+
static pure(a) {
|
|
30
|
+
return new Just(a);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var Just = class _Just extends Maybe {
|
|
34
|
+
constructor(\u503C) {
|
|
35
|
+
super();
|
|
36
|
+
this.\u503C = \u503C;
|
|
37
|
+
}
|
|
38
|
+
match(onJust, _onNothing) {
|
|
39
|
+
return onJust(this.\u503C);
|
|
40
|
+
}
|
|
41
|
+
map(f) {
|
|
42
|
+
return new _Just(f(this.\u503C));
|
|
43
|
+
}
|
|
44
|
+
bind(f) {
|
|
45
|
+
return f(this.\u503C);
|
|
46
|
+
}
|
|
47
|
+
isJust() {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
isNothing() {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
getJust() {
|
|
54
|
+
return this.\u503C;
|
|
55
|
+
}
|
|
56
|
+
getJustOrNull() {
|
|
57
|
+
return this.\u503C;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var Nothing = class _Nothing extends Maybe {
|
|
61
|
+
match(_onJust, onNothing) {
|
|
62
|
+
return onNothing();
|
|
63
|
+
}
|
|
64
|
+
map(_f) {
|
|
65
|
+
return new _Nothing();
|
|
66
|
+
}
|
|
67
|
+
bind(_f) {
|
|
68
|
+
return new _Nothing();
|
|
69
|
+
}
|
|
70
|
+
isJust() {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
isNothing() {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
getJustOrNull() {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
Just,
|
|
83
|
+
Maybe,
|
|
84
|
+
Nothing
|
|
85
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare abstract class Maybe<A> {
|
|
2
|
+
static pure<A>(a: A): Maybe<A>;
|
|
3
|
+
abstract map<B>(f: (a: A) => B): Maybe<B>;
|
|
4
|
+
abstract bind<B>(f: (a: A) => Maybe<B>): Maybe<B>;
|
|
5
|
+
abstract isJust(): this is Just<A>;
|
|
6
|
+
abstract isNothing(): this is Nothing<A>;
|
|
7
|
+
abstract getJustOrNull(): A | null;
|
|
8
|
+
abstract match<B>(onJust: (a: A) => B, onNothing: () => B): B;
|
|
9
|
+
}
|
|
10
|
+
declare class Just<A> extends Maybe<A> {
|
|
11
|
+
private 值;
|
|
12
|
+
constructor(值: A);
|
|
13
|
+
match<B>(onJust: (a: A) => B, _onNothing: () => B): B;
|
|
14
|
+
map<B>(f: (a: A) => B): Maybe<B>;
|
|
15
|
+
bind<B>(f: (a: A) => Maybe<B>): Maybe<B>;
|
|
16
|
+
isJust(): this is Just<A>;
|
|
17
|
+
isNothing(): this is Nothing<A>;
|
|
18
|
+
getJust(): A;
|
|
19
|
+
getJustOrNull(): A | null;
|
|
20
|
+
}
|
|
21
|
+
declare class Nothing<A> extends Maybe<A> {
|
|
22
|
+
match<B>(_onJust: (a: A) => B, onNothing: () => B): B;
|
|
23
|
+
map<B>(_f: (a: A) => B): Maybe<B>;
|
|
24
|
+
bind<B>(_f: (a: A) => Maybe<B>): Maybe<B>;
|
|
25
|
+
isJust(): this is Just<A>;
|
|
26
|
+
isNothing(): this is Nothing<A>;
|
|
27
|
+
getJustOrNull(): A | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { Just, Maybe, Nothing };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/task.ts
|
|
21
|
+
var task_exports = {};
|
|
22
|
+
__export(task_exports, {
|
|
23
|
+
Task: () => Task
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(task_exports);
|
|
26
|
+
var Task = class _Task {
|
|
27
|
+
constructor(f) {
|
|
28
|
+
this.f = f;
|
|
29
|
+
}
|
|
30
|
+
static pure(a) {
|
|
31
|
+
return new _Task(async () => a);
|
|
32
|
+
}
|
|
33
|
+
map(f) {
|
|
34
|
+
return new _Task(async () => f(await this.f()));
|
|
35
|
+
}
|
|
36
|
+
bind(f) {
|
|
37
|
+
return new _Task(async () => f(await this.f()).run());
|
|
38
|
+
}
|
|
39
|
+
run() {
|
|
40
|
+
return this.f();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
Task
|
|
46
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/maybe.ts
|
|
2
|
+
var Maybe = class {
|
|
3
|
+
static pure(a) {
|
|
4
|
+
return new Just(a);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var Just = class _Just extends Maybe {
|
|
8
|
+
constructor(\u503C) {
|
|
9
|
+
super();
|
|
10
|
+
this.\u503C = \u503C;
|
|
11
|
+
}
|
|
12
|
+
match(onJust, _onNothing) {
|
|
13
|
+
return onJust(this.\u503C);
|
|
14
|
+
}
|
|
15
|
+
map(f) {
|
|
16
|
+
return new _Just(f(this.\u503C));
|
|
17
|
+
}
|
|
18
|
+
bind(f) {
|
|
19
|
+
return f(this.\u503C);
|
|
20
|
+
}
|
|
21
|
+
isJust() {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
isNothing() {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
getJust() {
|
|
28
|
+
return this.\u503C;
|
|
29
|
+
}
|
|
30
|
+
getJustOrNull() {
|
|
31
|
+
return this.\u503C;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var Nothing = class _Nothing extends Maybe {
|
|
35
|
+
match(_onJust, onNothing) {
|
|
36
|
+
return onNothing();
|
|
37
|
+
}
|
|
38
|
+
map(_f) {
|
|
39
|
+
return new _Nothing();
|
|
40
|
+
}
|
|
41
|
+
bind(_f) {
|
|
42
|
+
return new _Nothing();
|
|
43
|
+
}
|
|
44
|
+
isJust() {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
isNothing() {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
getJustOrNull() {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
Maybe,
|
|
57
|
+
Just,
|
|
58
|
+
Nothing
|
|
59
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/task.ts
|
|
2
|
+
var Task = class _Task {
|
|
3
|
+
constructor(f) {
|
|
4
|
+
this.f = f;
|
|
5
|
+
}
|
|
6
|
+
static pure(a) {
|
|
7
|
+
return new _Task(async () => a);
|
|
8
|
+
}
|
|
9
|
+
map(f) {
|
|
10
|
+
return new _Task(async () => f(await this.f()));
|
|
11
|
+
}
|
|
12
|
+
bind(f) {
|
|
13
|
+
return new _Task(async () => f(await this.f()).run());
|
|
14
|
+
}
|
|
15
|
+
run() {
|
|
16
|
+
return this.f();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
Task
|
|
22
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/either.ts
|
|
2
|
+
var Either = class {
|
|
3
|
+
static pure(a) {
|
|
4
|
+
return new Right(a);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var Left = class _Left extends Either {
|
|
8
|
+
constructor(\u503C) {
|
|
9
|
+
super();
|
|
10
|
+
this.\u503C = \u503C;
|
|
11
|
+
}
|
|
12
|
+
map(_f) {
|
|
13
|
+
return new _Left(this.\u503C);
|
|
14
|
+
}
|
|
15
|
+
mapLeft(f) {
|
|
16
|
+
return new _Left(f(this.\u503C));
|
|
17
|
+
}
|
|
18
|
+
bind(_f) {
|
|
19
|
+
return new _Left(this.\u503C);
|
|
20
|
+
}
|
|
21
|
+
isLeft() {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
isRight() {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
getLeft() {
|
|
28
|
+
return this.\u503C;
|
|
29
|
+
}
|
|
30
|
+
getValue() {
|
|
31
|
+
return this.\u503C;
|
|
32
|
+
}
|
|
33
|
+
assertLeft() {
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
assertRight() {
|
|
37
|
+
throw new Error("\u65AD\u8A00\u5931\u8D25");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var Right = class _Right extends Either {
|
|
41
|
+
constructor(\u503C) {
|
|
42
|
+
super();
|
|
43
|
+
this.\u503C = \u503C;
|
|
44
|
+
}
|
|
45
|
+
map(f) {
|
|
46
|
+
return new _Right(f(this.\u503C));
|
|
47
|
+
}
|
|
48
|
+
mapLeft(_f) {
|
|
49
|
+
return new _Right(this.\u503C);
|
|
50
|
+
}
|
|
51
|
+
bind(f) {
|
|
52
|
+
return f(this.\u503C);
|
|
53
|
+
}
|
|
54
|
+
isLeft() {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
isRight() {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
getRight() {
|
|
61
|
+
return this.\u503C;
|
|
62
|
+
}
|
|
63
|
+
getValue() {
|
|
64
|
+
return this.\u503C;
|
|
65
|
+
}
|
|
66
|
+
assertLeft() {
|
|
67
|
+
throw new Error("\u65AD\u8A00\u5931\u8D25");
|
|
68
|
+
}
|
|
69
|
+
assertRight() {
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
Either,
|
|
76
|
+
Left,
|
|
77
|
+
Right
|
|
78
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
declare abstract class Either<L, R> {
|
|
2
|
+
static pure<L, R>(a: R): Either<L, R>;
|
|
3
|
+
abstract map<B>(_f: (a: R) => B): Either<L, B>;
|
|
4
|
+
abstract mapLeft<B>(f: (a: L) => B): Either<B, R>;
|
|
5
|
+
abstract bind<B>(_f: (a: R) => Either<L, B>): Either<L, B>;
|
|
6
|
+
abstract isLeft(): this is Left<L, R>;
|
|
7
|
+
abstract isRight(): this is Right<L, R>;
|
|
8
|
+
abstract getValue(): L | R;
|
|
9
|
+
abstract assertLeft(): Left<L, R>;
|
|
10
|
+
abstract assertRight(): Right<L, R>;
|
|
11
|
+
}
|
|
12
|
+
declare class Left<L, R> extends Either<L, R> {
|
|
13
|
+
private 值;
|
|
14
|
+
constructor(值: L);
|
|
15
|
+
map<B>(_f: (a: R) => B): Either<L, B>;
|
|
16
|
+
mapLeft<B>(f: (a: L) => B): Either<B, R>;
|
|
17
|
+
bind<B>(_f: (a: R) => Either<L, B>): Either<L, B>;
|
|
18
|
+
isLeft(): this is Left<L, R>;
|
|
19
|
+
isRight(): this is Right<L, R>;
|
|
20
|
+
getLeft(): L;
|
|
21
|
+
getValue(): L | R;
|
|
22
|
+
assertLeft(): Left<L, R>;
|
|
23
|
+
assertRight(): Right<L, R>;
|
|
24
|
+
}
|
|
25
|
+
declare class Right<L, R> extends Either<L, R> {
|
|
26
|
+
private 值;
|
|
27
|
+
constructor(值: R);
|
|
28
|
+
map<B>(f: (a: R) => B): Either<L, B>;
|
|
29
|
+
mapLeft<B>(_f: (a: L) => B): Either<B, R>;
|
|
30
|
+
bind<B>(f: (a: R) => Either<L, B>): Either<L, B>;
|
|
31
|
+
isLeft(): this is Left<L, R>;
|
|
32
|
+
isRight(): this is Right<L, R>;
|
|
33
|
+
getRight(): R;
|
|
34
|
+
getValue(): L | R;
|
|
35
|
+
assertLeft(): Left<L, R>;
|
|
36
|
+
assertRight(): Right<L, R>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { Either, Left, Right };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Either,
|
|
3
|
+
Left,
|
|
4
|
+
Right
|
|
5
|
+
} from "./chunk-WNXSHYAM.js";
|
|
6
|
+
import {
|
|
7
|
+
Just,
|
|
8
|
+
Maybe,
|
|
9
|
+
Nothing
|
|
10
|
+
} from "./chunk-LDWARHRU.js";
|
|
11
|
+
import {
|
|
12
|
+
Task
|
|
13
|
+
} from "./chunk-MUKICLFD.js";
|
|
14
|
+
export {
|
|
15
|
+
Either,
|
|
16
|
+
Just,
|
|
17
|
+
Left,
|
|
18
|
+
Maybe,
|
|
19
|
+
Nothing,
|
|
20
|
+
Right,
|
|
21
|
+
Task
|
|
22
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare abstract class Maybe<A> {
|
|
2
|
+
static pure<A>(a: A): Maybe<A>;
|
|
3
|
+
abstract map<B>(f: (a: A) => B): Maybe<B>;
|
|
4
|
+
abstract bind<B>(f: (a: A) => Maybe<B>): Maybe<B>;
|
|
5
|
+
abstract isJust(): this is Just<A>;
|
|
6
|
+
abstract isNothing(): this is Nothing<A>;
|
|
7
|
+
abstract getJustOrNull(): A | null;
|
|
8
|
+
abstract match<B>(onJust: (a: A) => B, onNothing: () => B): B;
|
|
9
|
+
}
|
|
10
|
+
declare class Just<A> extends Maybe<A> {
|
|
11
|
+
private 值;
|
|
12
|
+
constructor(值: A);
|
|
13
|
+
match<B>(onJust: (a: A) => B, _onNothing: () => B): B;
|
|
14
|
+
map<B>(f: (a: A) => B): Maybe<B>;
|
|
15
|
+
bind<B>(f: (a: A) => Maybe<B>): Maybe<B>;
|
|
16
|
+
isJust(): this is Just<A>;
|
|
17
|
+
isNothing(): this is Nothing<A>;
|
|
18
|
+
getJust(): A;
|
|
19
|
+
getJustOrNull(): A | null;
|
|
20
|
+
}
|
|
21
|
+
declare class Nothing<A> extends Maybe<A> {
|
|
22
|
+
match<B>(_onJust: (a: A) => B, onNothing: () => B): B;
|
|
23
|
+
map<B>(_f: (a: A) => B): Maybe<B>;
|
|
24
|
+
bind<B>(_f: (a: A) => Maybe<B>): Maybe<B>;
|
|
25
|
+
isJust(): this is Just<A>;
|
|
26
|
+
isNothing(): this is Nothing<A>;
|
|
27
|
+
getJustOrNull(): A | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { Just, Maybe, Nothing };
|
package/dist/esm/task.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lsby/ts-fp-data",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"require": "./dist/cjs/index.cjs",
|
|
7
|
+
"import": "./dist/esm/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.2.1",
|
|
15
|
+
"@types/node": "^20.12.10",
|
|
16
|
+
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
|
17
|
+
"@typescript-eslint/parser": "^7.8.0",
|
|
18
|
+
"bumpp": "^9.4.1",
|
|
19
|
+
"eslint": "^8.56.0",
|
|
20
|
+
"eslint-config-prettier": "^9.1.0",
|
|
21
|
+
"eslint-plugin-sort-class-members": "^1.20.0",
|
|
22
|
+
"eslint-plugin-unused-imports": "^3.2.0",
|
|
23
|
+
"prettier": "3.2.5",
|
|
24
|
+
"prettier-plugin-packagejson": "^2.5.0",
|
|
25
|
+
"tsup": "^8.0.2",
|
|
26
|
+
"tsx": "^4.9.3",
|
|
27
|
+
"typescript": "^5.4.5"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build:all": "npm run build:cjs && npm run build:esm",
|
|
31
|
+
"build:cjs": "tsup src/**/*.ts --format cjs --clean --dts -d dist/cjs",
|
|
32
|
+
"build:esm": "tsup src/**/*.ts --format esm --clean --dts -d dist/esm",
|
|
33
|
+
"other:clean": "rm -rf .parcel-cache dist",
|
|
34
|
+
"other:format": "prettier --write .",
|
|
35
|
+
"other:lint": "eslint . --fix",
|
|
36
|
+
"other:pub": "npm run other:typecheck && npm run build:all && bumpp && pnpm -r publish --access public",
|
|
37
|
+
"other:typecheck": "tsc --noEmit",
|
|
38
|
+
"other:typecheck:watch": "tsc --noEmit -w",
|
|
39
|
+
"run:start": "tsx src/index.ts"
|
|
40
|
+
}
|
|
41
|
+
}
|