@fable-org/fable-library-ts 1.10.0 → 2.0.0-beta.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/Result.ts CHANGED
@@ -1,196 +1,196 @@
1
- import { Union } from "./Types.js";
2
- import { union_type, TypeInfo } from "./Reflection.js";
3
- import { int32 } from "./Int32.js";
4
- import { equals } from "./Util.js";
5
- import { FSharpList, empty, singleton } from "./List.js";
6
- import { Option, some } from "./Option.js";
7
-
8
- export type FSharpResult$2_$union<T, TError> =
9
- | FSharpResult$2<T, TError, 0>
10
- | FSharpResult$2<T, TError, 1>
11
-
12
- export type FSharpResult$2_$cases<T, TError> = {
13
- 0: ["Ok", [T]],
14
- 1: ["Error", [TError]]
15
- }
16
-
17
- export function FSharpResult$2_Ok<T, TError>(ResultValue: T) {
18
- return new FSharpResult$2<T, TError, 0>(0, [ResultValue]);
19
- }
20
-
21
- export function FSharpResult$2_Error<T, TError>(ErrorValue: TError) {
22
- return new FSharpResult$2<T, TError, 1>(1, [ErrorValue]);
23
- }
24
-
25
- export class FSharpResult$2<T, TError, Tag extends keyof FSharpResult$2_$cases<T, TError>> extends Union<Tag, FSharpResult$2_$cases<T, TError>[Tag][0]> {
26
- constructor(readonly tag: Tag, readonly fields: FSharpResult$2_$cases<T, TError>[Tag][1]) {
27
- super();
28
- }
29
- cases() {
30
- return ["Ok", "Error"];
31
- }
32
- }
33
-
34
- export function FSharpResult$2_$reflection(gen0: TypeInfo, gen1: TypeInfo): TypeInfo {
35
- return union_type("FSharp.Core.FSharpResult`2", [gen0, gen1], FSharpResult$2, () => [[["ResultValue", gen0]], [["ErrorValue", gen1]]]);
36
- }
37
-
38
- export function Result_Map<a, b, c>(mapping: ((arg0: a) => b), result: FSharpResult$2_$union<a, c>): FSharpResult$2_$union<b, c> {
39
- if ((result.tag as int32) === /* Ok */ 0) {
40
- return FSharpResult$2_Ok<b, c>(mapping(result.fields[0] as any));
41
- }
42
- else {
43
- return FSharpResult$2_Error<b, c>(result.fields[0] as any);
44
- }
45
- }
46
-
47
- export function Result_MapError<a, b, c>(mapping: ((arg0: a) => b), result: FSharpResult$2_$union<c, a>): FSharpResult$2_$union<c, b> {
48
- if ((result.tag as int32) === /* Ok */ 0) {
49
- return FSharpResult$2_Ok<c, b>(result.fields[0] as any);
50
- }
51
- else {
52
- return FSharpResult$2_Error<c, b>(mapping(result.fields[0] as any));
53
- }
54
- }
55
-
56
- export function Result_Bind<a, b, c>(binder: ((arg0: a) => FSharpResult$2_$union<b, c>), result: FSharpResult$2_$union<a, c>): FSharpResult$2_$union<b, c> {
57
- if ((result.tag as int32) === /* Ok */ 0) {
58
- return binder(result.fields[0] as any);
59
- }
60
- else {
61
- return FSharpResult$2_Error<b, c>(result.fields[0] as any);
62
- }
63
- }
64
-
65
- export function Result_IsOk<a, b>(result: FSharpResult$2_$union<a, b>): boolean {
66
- if ((result.tag as int32) === /* Ok */ 0) {
67
- return true;
68
- }
69
- else {
70
- return false;
71
- }
72
- }
73
-
74
- export function Result_IsError<a, b>(result: FSharpResult$2_$union<a, b>): boolean {
75
- if ((result.tag as int32) === /* Ok */ 0) {
76
- return false;
77
- }
78
- else {
79
- return true;
80
- }
81
- }
82
-
83
- export function Result_Contains<a, b>(value: a, result: FSharpResult$2_$union<a, b>): boolean {
84
- if ((result.tag as int32) === /* Ok */ 0) {
85
- return equals(result.fields[0] as any, value);
86
- }
87
- else {
88
- return false;
89
- }
90
- }
91
-
92
- export function Result_Count<a, b>(result: FSharpResult$2_$union<a, b>): int32 {
93
- if ((result.tag as int32) === /* Ok */ 0) {
94
- return 1;
95
- }
96
- else {
97
- return 0;
98
- }
99
- }
100
-
101
- export function Result_DefaultValue<a, b>(defaultValue: a, result: FSharpResult$2_$union<a, b>): a {
102
- if ((result.tag as int32) === /* Ok */ 0) {
103
- return result.fields[0] as any;
104
- }
105
- else {
106
- return defaultValue;
107
- }
108
- }
109
-
110
- export function Result_DefaultWith<b, a>(defThunk: ((arg0: b) => a), result: FSharpResult$2_$union<a, b>): a {
111
- if ((result.tag as int32) === /* Ok */ 0) {
112
- return result.fields[0] as any;
113
- }
114
- else {
115
- return defThunk(result.fields[0] as any);
116
- }
117
- }
118
-
119
- export function Result_Exists<a, b>(predicate: ((arg0: a) => boolean), result: FSharpResult$2_$union<a, b>): boolean {
120
- if ((result.tag as int32) === /* Ok */ 0) {
121
- return predicate(result.fields[0] as any);
122
- }
123
- else {
124
- return false;
125
- }
126
- }
127
-
128
- export function Result_Fold<a, b, s>(folder: ((arg0: s, arg1: a) => s), state: s, result: FSharpResult$2_$union<a, b>): s {
129
- if ((result.tag as int32) === /* Ok */ 0) {
130
- return folder(state, result.fields[0] as any);
131
- }
132
- else {
133
- return state;
134
- }
135
- }
136
-
137
- export function Result_FoldBack<a, b, s>(folder: ((arg0: a, arg1: s) => s), result: FSharpResult$2_$union<a, b>, state: s): s {
138
- if ((result.tag as int32) === /* Ok */ 0) {
139
- return folder(result.fields[0] as any, state);
140
- }
141
- else {
142
- return state;
143
- }
144
- }
145
-
146
- export function Result_ForAll<a, b>(predicate: ((arg0: a) => boolean), result: FSharpResult$2_$union<a, b>): boolean {
147
- if ((result.tag as int32) === /* Ok */ 0) {
148
- return predicate(result.fields[0] as any);
149
- }
150
- else {
151
- return true;
152
- }
153
- }
154
-
155
- export function Result_Iterate<a, b>(action: ((arg0: a) => void), result: FSharpResult$2_$union<a, b>): void {
156
- if ((result.tag as int32) === /* Ok */ 0) {
157
- action(result.fields[0] as any);
158
- }
159
- }
160
-
161
- export function Result_ToArray<a, b>(result: FSharpResult$2_$union<a, b>): a[] {
162
- if ((result.tag as int32) === /* Ok */ 0) {
163
- return [result.fields[0] as any];
164
- }
165
- else {
166
- return [];
167
- }
168
- }
169
-
170
- export function Result_ToList<a, b>(result: FSharpResult$2_$union<a, b>): FSharpList<a> {
171
- if ((result.tag as int32) === /* Ok */ 0) {
172
- return singleton(result.fields[0] as any);
173
- }
174
- else {
175
- return empty<a>();
176
- }
177
- }
178
-
179
- export function Result_ToOption<a, b>(result: FSharpResult$2_$union<a, b>): Option<a> {
180
- if ((result.tag as int32) === /* Ok */ 0) {
181
- return some(result.fields[0] as any);
182
- }
183
- else {
184
- return undefined;
185
- }
186
- }
187
-
188
- export function Result_ToValueOption<a, b>(result: FSharpResult$2_$union<a, b>): Option<a> {
189
- if ((result.tag as int32) === /* Ok */ 0) {
190
- return some(result.fields[0] as any);
191
- }
192
- else {
193
- return undefined;
194
- }
195
- }
196
-
1
+ import { Union } from "./Types.js";
2
+ import { union_type, TypeInfo } from "./Reflection.js";
3
+ import { int32 } from "./Int32.js";
4
+ import { equals } from "./Util.js";
5
+ import { FSharpList, empty, singleton } from "./List.js";
6
+ import { Option, some } from "./Option.js";
7
+
8
+ export type FSharpResult$2_$union<T, TError> =
9
+ | FSharpResult$2<T, TError, 0>
10
+ | FSharpResult$2<T, TError, 1>
11
+
12
+ export type FSharpResult$2_$cases<T, TError> = {
13
+ 0: ["Ok", [T]],
14
+ 1: ["Error", [TError]]
15
+ }
16
+
17
+ export function FSharpResult$2_Ok<T, TError>(ResultValue: T) {
18
+ return new FSharpResult$2<T, TError, 0>(0, [ResultValue]);
19
+ }
20
+
21
+ export function FSharpResult$2_Error<T, TError>(ErrorValue: TError) {
22
+ return new FSharpResult$2<T, TError, 1>(1, [ErrorValue]);
23
+ }
24
+
25
+ export class FSharpResult$2<T, TError, Tag extends keyof FSharpResult$2_$cases<T, TError>> extends Union<Tag, FSharpResult$2_$cases<T, TError>[Tag][0]> {
26
+ constructor(readonly tag: Tag, readonly fields: FSharpResult$2_$cases<T, TError>[Tag][1]) {
27
+ super();
28
+ }
29
+ cases() {
30
+ return ["Ok", "Error"];
31
+ }
32
+ }
33
+
34
+ export function FSharpResult$2_$reflection(gen0: TypeInfo, gen1: TypeInfo): TypeInfo {
35
+ return union_type("FSharp.Core.FSharpResult`2", [gen0, gen1], FSharpResult$2, () => [[["ResultValue", gen0]], [["ErrorValue", gen1]]]);
36
+ }
37
+
38
+ export function Result_Map<a, b, c>(mapping: ((arg0: a) => b), result: FSharpResult$2_$union<a, c>): FSharpResult$2_$union<b, c> {
39
+ if ((result.tag as int32) === /* Ok */ 0) {
40
+ return FSharpResult$2_Ok<b, c>(mapping(result.fields[0] as any));
41
+ }
42
+ else {
43
+ return FSharpResult$2_Error<b, c>(result.fields[0] as any);
44
+ }
45
+ }
46
+
47
+ export function Result_MapError<a, b, c>(mapping: ((arg0: a) => b), result: FSharpResult$2_$union<c, a>): FSharpResult$2_$union<c, b> {
48
+ if ((result.tag as int32) === /* Ok */ 0) {
49
+ return FSharpResult$2_Ok<c, b>(result.fields[0] as any);
50
+ }
51
+ else {
52
+ return FSharpResult$2_Error<c, b>(mapping(result.fields[0] as any));
53
+ }
54
+ }
55
+
56
+ export function Result_Bind<a, b, c>(binder: ((arg0: a) => FSharpResult$2_$union<b, c>), result: FSharpResult$2_$union<a, c>): FSharpResult$2_$union<b, c> {
57
+ if ((result.tag as int32) === /* Ok */ 0) {
58
+ return binder(result.fields[0] as any);
59
+ }
60
+ else {
61
+ return FSharpResult$2_Error<b, c>(result.fields[0] as any);
62
+ }
63
+ }
64
+
65
+ export function Result_IsOk<a, b>(result: FSharpResult$2_$union<a, b>): boolean {
66
+ if ((result.tag as int32) === /* Ok */ 0) {
67
+ return true;
68
+ }
69
+ else {
70
+ return false;
71
+ }
72
+ }
73
+
74
+ export function Result_IsError<a, b>(result: FSharpResult$2_$union<a, b>): boolean {
75
+ if ((result.tag as int32) === /* Ok */ 0) {
76
+ return false;
77
+ }
78
+ else {
79
+ return true;
80
+ }
81
+ }
82
+
83
+ export function Result_Contains<a, b>(value: a, result: FSharpResult$2_$union<a, b>): boolean {
84
+ if ((result.tag as int32) === /* Ok */ 0) {
85
+ return equals(result.fields[0] as any, value);
86
+ }
87
+ else {
88
+ return false;
89
+ }
90
+ }
91
+
92
+ export function Result_Count<a, b>(result: FSharpResult$2_$union<a, b>): int32 {
93
+ if ((result.tag as int32) === /* Ok */ 0) {
94
+ return 1;
95
+ }
96
+ else {
97
+ return 0;
98
+ }
99
+ }
100
+
101
+ export function Result_DefaultValue<a, b>(defaultValue: a, result: FSharpResult$2_$union<a, b>): a {
102
+ if ((result.tag as int32) === /* Ok */ 0) {
103
+ return result.fields[0] as any;
104
+ }
105
+ else {
106
+ return defaultValue;
107
+ }
108
+ }
109
+
110
+ export function Result_DefaultWith<b, a>(defThunk: ((arg0: b) => a), result: FSharpResult$2_$union<a, b>): a {
111
+ if ((result.tag as int32) === /* Ok */ 0) {
112
+ return result.fields[0] as any;
113
+ }
114
+ else {
115
+ return defThunk(result.fields[0] as any);
116
+ }
117
+ }
118
+
119
+ export function Result_Exists<a, b>(predicate: ((arg0: a) => boolean), result: FSharpResult$2_$union<a, b>): boolean {
120
+ if ((result.tag as int32) === /* Ok */ 0) {
121
+ return predicate(result.fields[0] as any);
122
+ }
123
+ else {
124
+ return false;
125
+ }
126
+ }
127
+
128
+ export function Result_Fold<a, b, s>(folder: ((arg0: s, arg1: a) => s), state: s, result: FSharpResult$2_$union<a, b>): s {
129
+ if ((result.tag as int32) === /* Ok */ 0) {
130
+ return folder(state, result.fields[0] as any);
131
+ }
132
+ else {
133
+ return state;
134
+ }
135
+ }
136
+
137
+ export function Result_FoldBack<a, b, s>(folder: ((arg0: a, arg1: s) => s), result: FSharpResult$2_$union<a, b>, state: s): s {
138
+ if ((result.tag as int32) === /* Ok */ 0) {
139
+ return folder(result.fields[0] as any, state);
140
+ }
141
+ else {
142
+ return state;
143
+ }
144
+ }
145
+
146
+ export function Result_ForAll<a, b>(predicate: ((arg0: a) => boolean), result: FSharpResult$2_$union<a, b>): boolean {
147
+ if ((result.tag as int32) === /* Ok */ 0) {
148
+ return predicate(result.fields[0] as any);
149
+ }
150
+ else {
151
+ return true;
152
+ }
153
+ }
154
+
155
+ export function Result_Iterate<a, b>(action: ((arg0: a) => void), result: FSharpResult$2_$union<a, b>): void {
156
+ if ((result.tag as int32) === /* Ok */ 0) {
157
+ action(result.fields[0] as any);
158
+ }
159
+ }
160
+
161
+ export function Result_ToArray<a, b>(result: FSharpResult$2_$union<a, b>): a[] {
162
+ if ((result.tag as int32) === /* Ok */ 0) {
163
+ return [result.fields[0] as any];
164
+ }
165
+ else {
166
+ return [];
167
+ }
168
+ }
169
+
170
+ export function Result_ToList<a, b>(result: FSharpResult$2_$union<a, b>): FSharpList<a> {
171
+ if ((result.tag as int32) === /* Ok */ 0) {
172
+ return singleton(result.fields[0] as any);
173
+ }
174
+ else {
175
+ return empty<a>();
176
+ }
177
+ }
178
+
179
+ export function Result_ToOption<a, b>(result: FSharpResult$2_$union<a, b>): Option<a> {
180
+ if ((result.tag as int32) === /* Ok */ 0) {
181
+ return some(result.fields[0] as any);
182
+ }
183
+ else {
184
+ return undefined;
185
+ }
186
+ }
187
+
188
+ export function Result_ToValueOption<a, b>(result: FSharpResult$2_$union<a, b>): Option<a> {
189
+ if ((result.tag as int32) === /* Ok */ 0) {
190
+ return some(result.fields[0] as any);
191
+ }
192
+ else {
193
+ return undefined;
194
+ }
195
+ }
196
+