@glutinum/cli 0.14.0 → 1.0.0-beta.1
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/Glutinum.Converter/FsharpAST.js +38 -4
- package/dist/Glutinum.Converter/Generate.js +15 -7
- package/dist/Glutinum.Converter/GlueAST.js +45 -36
- package/dist/Glutinum.Converter/Hosting.js +918 -0
- package/dist/Glutinum.Converter/Merge.js +218 -82
- package/dist/Glutinum.Converter/Packages.js +44 -8
- package/dist/Glutinum.Converter/Printer.js +77 -49
- package/dist/Glutinum.Converter/Read.js +8 -8
- package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +7 -7
- package/dist/Glutinum.Converter/Reader/Declaration.js +26 -26
- package/dist/Glutinum.Converter/Reader/Documentation.js +37 -36
- package/dist/Glutinum.Converter/Reader/ExportAssignment.js +5 -5
- package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +31 -19
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +6 -7
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +36 -29
- package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +3 -3
- package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +82 -4
- package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +3 -3
- package/dist/Glutinum.Converter/Reader/Node.js +20 -20
- package/dist/Glutinum.Converter/Reader/Parameters.js +7 -7
- package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
- package/dist/Glutinum.Converter/Reader/TypeNode.js +291 -232
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +8 -8
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +108 -40
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +2 -2
- package/dist/Glutinum.Converter/Reader/Types.js +6 -6
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +7 -6
- package/dist/Glutinum.Converter/Reader/Utils.js +106 -56
- package/dist/Glutinum.Converter/Transform.js +2057 -700
- package/dist/Glutinum.Converter/TypeScript.Extensions.js +194 -202
- package/dist/Glutinum.Converter/Utils/Naming.js +7 -0
- package/dist/Glutinum.Converter/Utils/String.js +2 -2
- package/dist/Program.js +38 -26
- package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs +89 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs.js +105 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/Fable.Promise.fableproj +25 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs +842 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs.js +232 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs +31 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs +235 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs.js +384 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AssemblyInfo.fs +19 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs +287 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs.js +128 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOption.fs +127 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs +174 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs.js +37 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResult.fs +483 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs +201 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs +87 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs.js +26 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs +236 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidation.fs +185 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs +186 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationOp.fs +35 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/FsToolkit.ErrorHandling.fableproj +69 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs +276 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs.js +364 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Nullness.fs +81 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Option.fs +462 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs +139 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs.js +48 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionOp.fs +21 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs +88 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs.js +30 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs +200 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidation.fs +34 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs +244 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs +731 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs.js +45 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs +140 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs.js +23 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOp.fs +45 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs +201 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs.js +65 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs +135 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionOp.fs +57 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs +503 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs.js +295 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Validation.fs +167 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs +142 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationOp.fs +35 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueOption.fs +148 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOption.fs +102 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionCE.fs +587 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionOp.fs +10 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Array.js +1348 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Async.js +163 -0
- package/dist/fable_modules/fable-library-js.5.17.2/AsyncBuilder.js +204 -0
- package/dist/fable_modules/fable-library-js.5.17.2/BigInt.js +307 -0
- package/dist/fable_modules/fable-library-js.5.17.2/BitConverter.js +138 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Boolean.js +22 -0
- package/dist/fable_modules/fable-library-js.5.17.2/CHANGELOG.md +348 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Char.js +202 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Choice.js +184 -0
- package/dist/fable_modules/fable-library-js.5.17.2/CollectionUtil.js +182 -0
- package/dist/fable_modules/fable-library-js.5.17.2/ConditionalWeakTable.js +21 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Date.js +834 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateOffset.js +252 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateOnly.js +124 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateOnlyTemporal.js +146 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateTimeFormat.js +523 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateTimeOffsetTemporal.js +283 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateTimeTemporal.js +243 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Decimal.js +238 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Directory.js +11 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Double.js +53 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Encoding.js +185 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Environment.js +3 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Event.js +102 -0
- package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Collections.js +45 -0
- package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.CompilerServices.js +27 -0
- package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.js +156 -0
- package/dist/fable_modules/fable-library-js.5.17.2/File.js +27 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Global.js +29 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Guid.js +163 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Int32.js +135 -0
- package/dist/fable_modules/fable-library-js.5.17.2/List.js +1337 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Long.js +38 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MailboxProcessor.js +100 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Map.js +1400 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MapUtil.js +130 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MutableMap.js +339 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MutableSet.js +233 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Native.js +14 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Numeric.js +112 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Observable.js +115 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Option.js +87 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Path.js +31 -0
- package/dist/fable_modules/fable-library-js.5.17.2/README.md +3 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Random.js +172 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Range.js +45 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Reflection.js +489 -0
- package/dist/fable_modules/fable-library-js.5.17.2/RegExp.js +170 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Result.js +165 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Seq.js +1504 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Seq2.js +111 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Set.js +1829 -0
- package/dist/fable_modules/fable-library-js.5.17.2/String.js +731 -0
- package/dist/fable_modules/fable-library-js.5.17.2/System.Collections.Generic.js +333 -0
- package/dist/fable_modules/fable-library-js.5.17.2/System.Text.js +200 -0
- package/dist/fable_modules/fable-library-js.5.17.2/System.js +289 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Task.js +27 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TaskBuilder.js +72 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeOnly.js +122 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeOnlyTemporal.js +142 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeSpan.js +180 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeSpanTemporal.js +259 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Timer.js +67 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Types.js +198 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Unicode.13.0.0.js +4 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Uri.js +165 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Util.js +807 -0
- package/dist/fable_modules/fable-library-js.5.17.2/big.d.ts +338 -0
- package/dist/fable_modules/fable-library-js.5.17.2/lib/big.js +829 -0
- package/dist/fable_modules/fable-library-js.5.17.2/package.json +24 -0
- package/dist/fable_modules/fable-library-js.5.17.2/quotation.js +682 -0
- package/package.json +2 -2
- package/dist/Glutinum.Converter/TypeScript.js +0 -12
- package/src/Glutinum.Converter/js/bootstrap.js +0 -123
- package/src/Glutinum.Converter/js/host.js +0 -144
- package/src/Glutinum.Converter/js/npm.js +0 -137
- package/src/Glutinum.Converter/js/resolve.js +0 -402
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
|
|
2
|
+
import { empty } from "../fable-library-js.5.17.2/Seq.js";
|
|
3
|
+
import { FSharpResult$2 } from "../fable-library-js.5.17.2/Result.js";
|
|
4
|
+
import { Operators_NullArg, Operators_IsNull } from "../fable-library-js.5.17.2/FSharp.Core.js";
|
|
5
|
+
import { disposeSafe, getEnumerator, defaultOf } from "../fable-library-js.5.17.2/Util.js";
|
|
6
|
+
import { singleton } from "../fable-library-js.5.17.2/AsyncBuilder.js";
|
|
7
|
+
import { ArgumentNullException_$ctor_Z721C83C5 } from "../fable-library-js.5.17.2/System.js";
|
|
8
|
+
import { value as value_1 } from "../fable-library-js.5.17.2/Option.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Applies a function to each element of a sequence and returns a single result
|
|
12
|
+
*/
|
|
13
|
+
export function traverseResultM(f, xs) {
|
|
14
|
+
const state = new FSharpResult$2(/* Ok */ 0, [empty()]);
|
|
15
|
+
const xs_1 = xs;
|
|
16
|
+
if (Operators_IsNull(xs_1)) {
|
|
17
|
+
Operators_NullArg("xs");
|
|
18
|
+
}
|
|
19
|
+
if (state.tag === 0) {
|
|
20
|
+
const oks = Array.from(state.fields[0]);
|
|
21
|
+
let err = defaultOf();
|
|
22
|
+
let ok = true;
|
|
23
|
+
const e_1 = getEnumerator(xs_1);
|
|
24
|
+
try {
|
|
25
|
+
while (ok && e_1["System.Collections.IEnumerator.MoveNext"]()) {
|
|
26
|
+
const matchValue = f(e_1["System.Collections.Generic.IEnumerator`1.get_Current"]());
|
|
27
|
+
if (matchValue.tag === 1) {
|
|
28
|
+
err = matchValue.fields[0];
|
|
29
|
+
ok = false;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
void (oks.push(matchValue.fields[0]));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return ok ? (new FSharpResult$2(/* Ok */ 0, [oks.slice()])) : (new FSharpResult$2(/* Error */ 1, [err]));
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
disposeSafe(e_1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return new FSharpResult$2(/* Error */ 1, [state.fields[0]]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Converts a sequence of results into a single result
|
|
48
|
+
*/
|
|
49
|
+
export function sequenceResultM(xs) {
|
|
50
|
+
return traverseResultM((x) => x, xs);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Applies a function to each element of a sequence and returns a single result
|
|
55
|
+
*/
|
|
56
|
+
export function traverseResultA(f, xs) {
|
|
57
|
+
const state = new FSharpResult$2(/* Ok */ 0, [empty()]);
|
|
58
|
+
const f_1 = f;
|
|
59
|
+
const xs_1 = xs;
|
|
60
|
+
if (Operators_IsNull(xs_1)) {
|
|
61
|
+
Operators_NullArg("xs");
|
|
62
|
+
}
|
|
63
|
+
if (state.tag === 0) {
|
|
64
|
+
const oks = Array.from(state.fields[0]);
|
|
65
|
+
const errs_1 = [];
|
|
66
|
+
const enumerator_1 = getEnumerator(xs_1);
|
|
67
|
+
try {
|
|
68
|
+
while (enumerator_1["System.Collections.IEnumerator.MoveNext"]()) {
|
|
69
|
+
const matchValue_1 = f_1(enumerator_1["System.Collections.Generic.IEnumerator`1.get_Current"]());
|
|
70
|
+
if (matchValue_1.tag === 1) {
|
|
71
|
+
void (errs_1.push(matchValue_1.fields[0]));
|
|
72
|
+
}
|
|
73
|
+
else if (errs_1.length === 0) {
|
|
74
|
+
void (oks.push(matchValue_1.fields[0]));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
disposeSafe(enumerator_1);
|
|
80
|
+
}
|
|
81
|
+
if (errs_1.length === 0) {
|
|
82
|
+
return new FSharpResult$2(/* Ok */ 0, [oks.slice()]);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return new FSharpResult$2(/* Error */ 1, [errs_1.slice()]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const errs = Array.from(state.fields[0]);
|
|
90
|
+
const enumerator = getEnumerator(xs_1);
|
|
91
|
+
try {
|
|
92
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
93
|
+
const matchValue = f_1(enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]());
|
|
94
|
+
if (matchValue.tag === 0) {
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
void (errs.push(matchValue.fields[0]));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
disposeSafe(enumerator);
|
|
103
|
+
}
|
|
104
|
+
return new FSharpResult$2(/* Error */ 1, [errs.slice()]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Converts a sequence of results into a single result
|
|
110
|
+
*/
|
|
111
|
+
export function sequenceResultA(xs) {
|
|
112
|
+
return traverseResultA((x) => x, xs);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Applies a function to each element of a sequence and returns a single async result
|
|
117
|
+
*/
|
|
118
|
+
export function traverseAsyncResultM(f, xs) {
|
|
119
|
+
const state = singleton.Delay(() => singleton.Return(new FSharpResult$2(/* Ok */ 0, [empty()])));
|
|
120
|
+
const xs_1 = xs;
|
|
121
|
+
if (Operators_IsNull(xs_1)) {
|
|
122
|
+
Operators_NullArg("xs");
|
|
123
|
+
}
|
|
124
|
+
return singleton.Delay(() => singleton.Bind(state, (_arg) => {
|
|
125
|
+
if (_arg.tag === 0) {
|
|
126
|
+
const oks = Array.from(_arg.fields[0]);
|
|
127
|
+
let err = defaultOf();
|
|
128
|
+
let ok = true;
|
|
129
|
+
return singleton.Using(getEnumerator(xs_1), (_arg_1) => {
|
|
130
|
+
const e_1 = _arg_1;
|
|
131
|
+
return singleton.Combine(singleton.While(() => (ok && e_1["System.Collections.IEnumerator.MoveNext"]()), singleton.Delay(() => singleton.Bind(f(e_1["System.Collections.Generic.IEnumerator`1.get_Current"]()), (_arg_2) => {
|
|
132
|
+
if (_arg_2.tag === 1) {
|
|
133
|
+
err = _arg_2.fields[0];
|
|
134
|
+
ok = false;
|
|
135
|
+
return singleton.Zero();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
void (oks.push(_arg_2.fields[0]));
|
|
139
|
+
return singleton.Zero();
|
|
140
|
+
}
|
|
141
|
+
}))), singleton.Delay(() => singleton.Return(ok ? (new FSharpResult$2(/* Ok */ 0, [oks.slice()])) : (new FSharpResult$2(/* Error */ 1, [err])))));
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return singleton.Return(new FSharpResult$2(/* Error */ 1, [_arg.fields[0]]));
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Converts a sequence of async results into a single async result
|
|
152
|
+
*/
|
|
153
|
+
export function sequenceAsyncResultM(xs) {
|
|
154
|
+
return traverseAsyncResultM((x) => x, xs);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Applies a function to each element of a sequence and returns a single async result
|
|
159
|
+
*/
|
|
160
|
+
export function traverseAsyncResultA(f, xs) {
|
|
161
|
+
const state = singleton.Delay(() => singleton.Return(new FSharpResult$2(/* Ok */ 0, [empty()])));
|
|
162
|
+
const f_1 = f;
|
|
163
|
+
let xs_1_1;
|
|
164
|
+
const value = xs;
|
|
165
|
+
if (Operators_IsNull(value)) {
|
|
166
|
+
throw ArgumentNullException_$ctor_Z721C83C5("xs");
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
xs_1_1 = value;
|
|
170
|
+
}
|
|
171
|
+
return singleton.Delay(() => singleton.Bind(state, (_arg) => {
|
|
172
|
+
if (_arg.tag === 0) {
|
|
173
|
+
const oks = Array.from(_arg.fields[0]);
|
|
174
|
+
const errs_1 = [];
|
|
175
|
+
return singleton.Combine(singleton.For(xs_1_1, (_arg_3) => singleton.Bind(f_1(_arg_3), (_arg_4) => {
|
|
176
|
+
if (_arg_4.tag === 1) {
|
|
177
|
+
void (errs_1.push(_arg_4.fields[0]));
|
|
178
|
+
return singleton.Zero();
|
|
179
|
+
}
|
|
180
|
+
else if (errs_1.length === 0) {
|
|
181
|
+
void (oks.push(_arg_4.fields[0]));
|
|
182
|
+
return singleton.Zero();
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
return singleton.Zero();
|
|
186
|
+
}
|
|
187
|
+
})), singleton.Delay(() => ((errs_1.length === 0) ? singleton.Return(new FSharpResult$2(/* Ok */ 0, [oks.slice()])) : singleton.Return(new FSharpResult$2(/* Error */ 1, [errs_1.slice()])))));
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const errs = Array.from(_arg.fields[0]);
|
|
191
|
+
return singleton.Combine(singleton.For(xs_1_1, (_arg_1) => singleton.Bind(f_1(_arg_1), (_arg_2) => {
|
|
192
|
+
if (_arg_2.tag === 1) {
|
|
193
|
+
void (errs.push(_arg_2.fields[0]));
|
|
194
|
+
return singleton.Zero();
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return singleton.Zero();
|
|
198
|
+
}
|
|
199
|
+
})), singleton.Delay(() => singleton.Return(new FSharpResult$2(/* Error */ 1, [errs.slice()]))));
|
|
200
|
+
}
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Converts a sequence of async results into a single async result
|
|
206
|
+
*/
|
|
207
|
+
export function sequenceAsyncResultA(xs) {
|
|
208
|
+
return traverseAsyncResultA((x) => x, xs);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Applies a function to each element of a sequence and returns a single option
|
|
213
|
+
*/
|
|
214
|
+
export function traverseOptionM(f, xs) {
|
|
215
|
+
const state = empty();
|
|
216
|
+
const xs_1 = xs;
|
|
217
|
+
if (Operators_IsNull(xs_1)) {
|
|
218
|
+
Operators_NullArg("xs");
|
|
219
|
+
}
|
|
220
|
+
if (state != null) {
|
|
221
|
+
const initialValues = state;
|
|
222
|
+
const values = Array.from(initialValues);
|
|
223
|
+
let ok = true;
|
|
224
|
+
const enumerator = getEnumerator(xs_1);
|
|
225
|
+
try {
|
|
226
|
+
while (ok && enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
227
|
+
const matchValue = f(enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]());
|
|
228
|
+
if (matchValue == null) {
|
|
229
|
+
ok = false;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
const value = value_1(matchValue);
|
|
233
|
+
void (values.push(value));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return ok ? values.slice() : undefined;
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
disposeSafe(enumerator);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Converts a sequence of options into a single option
|
|
249
|
+
*/
|
|
250
|
+
export function sequenceOptionM(xs) {
|
|
251
|
+
return traverseOptionM((x) => x, xs);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Applies a function to each element of a sequence and returns a single async option
|
|
256
|
+
*/
|
|
257
|
+
export function traverseAsyncOptionM(f, xs) {
|
|
258
|
+
const state = singleton.Delay(() => singleton.Return(empty()));
|
|
259
|
+
const xs_1 = xs;
|
|
260
|
+
if (Operators_IsNull(xs_1)) {
|
|
261
|
+
Operators_NullArg("xs");
|
|
262
|
+
}
|
|
263
|
+
return singleton.Delay(() => singleton.Bind(state, (_arg) => {
|
|
264
|
+
if (_arg != null) {
|
|
265
|
+
const initialValues = _arg;
|
|
266
|
+
const values = Array.from(initialValues);
|
|
267
|
+
let ok = true;
|
|
268
|
+
return singleton.Using(getEnumerator(xs_1), (_arg_1) => {
|
|
269
|
+
const enumerator = _arg_1;
|
|
270
|
+
return singleton.Combine(singleton.While(() => (ok && enumerator["System.Collections.IEnumerator.MoveNext"]()), singleton.Delay(() => singleton.Bind(f(enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]()), (_arg_2) => {
|
|
271
|
+
if (_arg_2 == null) {
|
|
272
|
+
ok = false;
|
|
273
|
+
return singleton.Zero();
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
const value = value_1(_arg_2);
|
|
277
|
+
void (values.push(value));
|
|
278
|
+
return singleton.Zero();
|
|
279
|
+
}
|
|
280
|
+
}))), singleton.Delay(() => singleton.Return(ok ? values.slice() : undefined)));
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
return singleton.Return(undefined);
|
|
285
|
+
}
|
|
286
|
+
}));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Converts a sequence of async options into a single async option
|
|
291
|
+
*/
|
|
292
|
+
export function sequenceAsyncOptionM(xs) {
|
|
293
|
+
return traverseAsyncOptionM((x) => x, xs);
|
|
294
|
+
}
|
|
295
|
+
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
namespace FsToolkit.ErrorHandling
|
|
2
|
+
|
|
3
|
+
/// Validation<'a, 'err> is defined as Result<'a, 'err list> meaning you can use many of the functions found in the Result module.
|
|
4
|
+
type Validation<'ok, 'error> = Result<'ok, 'error list>
|
|
5
|
+
|
|
6
|
+
[<RequireQualifiedAccess>]
|
|
7
|
+
module Validation =
|
|
8
|
+
|
|
9
|
+
let inline ok (value: 'ok) : Validation<'ok, 'error> = Ok value
|
|
10
|
+
let inline error (error: 'error) : Validation<'ok, 'error> = Error [ error ]
|
|
11
|
+
|
|
12
|
+
let inline ofResult (result: Result<'ok, 'error>) : Validation<'ok, 'error> =
|
|
13
|
+
Result.mapError List.singleton result
|
|
14
|
+
|
|
15
|
+
let inline ofChoice (choice: Choice<'ok, 'error>) : Validation<'ok, 'error> =
|
|
16
|
+
match choice with
|
|
17
|
+
| Choice1Of2 x -> ok x
|
|
18
|
+
| Choice2Of2 e -> error e
|
|
19
|
+
|
|
20
|
+
let inline apply
|
|
21
|
+
(applier: Validation<'okInput -> 'okOutput, 'error>)
|
|
22
|
+
(input: Validation<'okInput, 'error>)
|
|
23
|
+
: Validation<'okOutput, 'error> =
|
|
24
|
+
match applier, input with
|
|
25
|
+
| Ok f, Ok x -> Ok(f x)
|
|
26
|
+
| Error errs, Ok _
|
|
27
|
+
| Ok _, Error errs -> Error errs
|
|
28
|
+
| Error errs1, Error errs2 ->
|
|
29
|
+
Error(
|
|
30
|
+
errs1
|
|
31
|
+
@ errs2
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Returns <paramref name="result"/> if it is <c>Ok</c>, otherwise returns <paramref name="ifError"/>
|
|
36
|
+
/// </summary>
|
|
37
|
+
/// <param name="ifError">The value to use if <paramref name="result"/> is <c>Error</c></param>
|
|
38
|
+
/// <param name="result">The input result.</param>
|
|
39
|
+
/// <remarks>
|
|
40
|
+
/// </remarks>
|
|
41
|
+
/// <example>
|
|
42
|
+
/// <code>
|
|
43
|
+
/// Error (["First"]) |> Validation.orElse (Error (["Second"])) // evaluates to Error (["Second"])
|
|
44
|
+
/// Error (["First"]) |> Validation.orElseWith (Ok ("Second")) // evaluates to Ok ("Second")
|
|
45
|
+
/// Ok ("First") |> Validation.orElseWith (Error (["Second"])) // evaluates to Ok ("First")
|
|
46
|
+
/// Ok ("First") |> Validation.orElseWith (Ok ("Second")) // evaluates to Ok ("First")
|
|
47
|
+
/// </code>
|
|
48
|
+
/// </example>
|
|
49
|
+
/// <returns>
|
|
50
|
+
/// The result if the result is Ok, else returns <paramref name="ifError"/>.
|
|
51
|
+
/// </returns>
|
|
52
|
+
let inline orElse
|
|
53
|
+
(ifError: Validation<'ok, 'errorOutput>)
|
|
54
|
+
(result: Validation<'ok, 'errorInput>)
|
|
55
|
+
: Validation<'ok, 'errorOutput> =
|
|
56
|
+
result
|
|
57
|
+
|> Result.either ok (fun _ -> ifError)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
/// <summary>
|
|
61
|
+
/// Returns <paramref name="result"/> if it is <c>Ok</c>, otherwise executes <paramref name="ifErrorFunc"/> and returns the result.
|
|
62
|
+
/// </summary>
|
|
63
|
+
/// <param name="ifErrorFunc">A function that provides an alternate result when evaluated.</param>
|
|
64
|
+
/// <param name="result">The input result.</param>
|
|
65
|
+
/// <remarks>
|
|
66
|
+
/// <paramref name="ifErrorFunc"/> is not executed unless <paramref name="result"/> is an <c>Error</c>.
|
|
67
|
+
/// </remarks>
|
|
68
|
+
/// <example>
|
|
69
|
+
/// <code>
|
|
70
|
+
/// Error (["First"]) |> Validation.orElseWith (fun _ -> Error (["Second"])) // evaluates to Error (["Second"])
|
|
71
|
+
/// Error (["First"]) |> Validation.orElseWith (fun _ -> Ok ("Second")) // evaluates to Ok ("Second")
|
|
72
|
+
/// Ok ("First") |> Validation.orElseWith (fun _ -> Error (["Second"])) // evaluates to Ok ("First")
|
|
73
|
+
/// Ok ("First") |> Validation.orElseWith (fun _ -> Ok ("Second")) // evaluates to Ok ("First")
|
|
74
|
+
/// </code>
|
|
75
|
+
/// </example>
|
|
76
|
+
/// <returns>
|
|
77
|
+
/// The result if the result is Ok, else the result of executing <paramref name="ifErrorFunc"/>.
|
|
78
|
+
/// </returns>
|
|
79
|
+
let inline orElseWith
|
|
80
|
+
([<InlineIfLambda>] ifErrorFunc: 'errorInput list -> Validation<'ok, 'errorOutput>)
|
|
81
|
+
(result: Validation<'ok, 'errorInput>)
|
|
82
|
+
: Validation<'ok, 'errorOutput> =
|
|
83
|
+
result
|
|
84
|
+
|> Result.either ok ifErrorFunc
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
let inline map
|
|
88
|
+
([<InlineIfLambda>] mapper: 'okInput -> 'okOutput)
|
|
89
|
+
(input: Validation<'okInput, 'error>)
|
|
90
|
+
: Validation<'okOutput, 'error> =
|
|
91
|
+
Result.map mapper input
|
|
92
|
+
|
|
93
|
+
let inline map2
|
|
94
|
+
([<InlineIfLambda>] mapper: 'okInput1 -> 'okInput2 -> 'okOutput)
|
|
95
|
+
(input1: Validation<'okInput1, 'error>)
|
|
96
|
+
(input2: Validation<'okInput2, 'error>)
|
|
97
|
+
: Validation<'okOutput, 'error> =
|
|
98
|
+
match input1, input2 with
|
|
99
|
+
| Ok x, Ok y -> Ok(mapper x y)
|
|
100
|
+
| Ok _, Error errs -> Error errs
|
|
101
|
+
| Error errs, Ok _ -> Error errs
|
|
102
|
+
| Error errs1, Error errs2 ->
|
|
103
|
+
Error(
|
|
104
|
+
errs1
|
|
105
|
+
@ errs2
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
let inline map3
|
|
109
|
+
([<InlineIfLambda>] mapper: 'okInput1 -> 'okInput2 -> 'okInput3 -> 'okOutput)
|
|
110
|
+
(input1: Validation<'okInput1, 'error>)
|
|
111
|
+
(input2: Validation<'okInput2, 'error>)
|
|
112
|
+
(input3: Validation<'okInput3, 'error>)
|
|
113
|
+
: Validation<'okOutput, 'error> =
|
|
114
|
+
match input1, input2, input3 with
|
|
115
|
+
| Ok x, Ok y, Ok z -> Ok(mapper x y z)
|
|
116
|
+
| Error errs, Ok _, Ok _ -> Error errs
|
|
117
|
+
| Ok _, Error errs, Ok _ -> Error errs
|
|
118
|
+
| Ok _, Ok _, Error errs -> Error errs
|
|
119
|
+
| Error errs1, Error errs2, Ok _ ->
|
|
120
|
+
Error(
|
|
121
|
+
errs1
|
|
122
|
+
@ errs2
|
|
123
|
+
)
|
|
124
|
+
| Ok _, Error errs1, Error errs2 ->
|
|
125
|
+
Error(
|
|
126
|
+
errs1
|
|
127
|
+
@ errs2
|
|
128
|
+
)
|
|
129
|
+
| Error errs1, Ok _, Error errs2 ->
|
|
130
|
+
Error(
|
|
131
|
+
errs1
|
|
132
|
+
@ errs2
|
|
133
|
+
)
|
|
134
|
+
| Error errs1, Error errs2, Error errs3 ->
|
|
135
|
+
Error(
|
|
136
|
+
errs1
|
|
137
|
+
@ errs2
|
|
138
|
+
@ errs3
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
let inline mapError
|
|
142
|
+
([<InlineIfLambda>] errorMapper: 'errorInput -> 'errorOutput)
|
|
143
|
+
(input: Validation<'ok, 'errorInput>)
|
|
144
|
+
: Validation<'ok, 'errorOutput> =
|
|
145
|
+
Result.mapError (List.map errorMapper) input
|
|
146
|
+
|
|
147
|
+
let inline mapErrors
|
|
148
|
+
([<InlineIfLambda>] errorMapper: 'errorInput list -> 'errorOutput list)
|
|
149
|
+
(input: Validation<'ok, 'errorInput>)
|
|
150
|
+
: Validation<'ok, 'errorOutput> =
|
|
151
|
+
Result.mapError (errorMapper) input
|
|
152
|
+
|
|
153
|
+
let inline bind
|
|
154
|
+
([<InlineIfLambda>] binder: 'okInput -> Validation<'okOutput, 'error>)
|
|
155
|
+
(input: Validation<'okInput, 'error>)
|
|
156
|
+
: Validation<'okOutput, 'error> =
|
|
157
|
+
Result.bind binder input
|
|
158
|
+
|
|
159
|
+
let inline zip
|
|
160
|
+
(left: Validation<'left, 'error>)
|
|
161
|
+
(right: Validation<'right, 'error>)
|
|
162
|
+
: Validation<'left * 'right, 'error> =
|
|
163
|
+
match left, right with
|
|
164
|
+
| Ok x1res, Ok x2res -> Ok(x1res, x2res)
|
|
165
|
+
| Error e, Ok _ -> Error e
|
|
166
|
+
| Ok _, Error e -> Error e
|
|
167
|
+
| Error e1, Error e2 -> Error(e1 @ e2)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
namespace FsToolkit.ErrorHandling
|
|
2
|
+
|
|
3
|
+
open System
|
|
4
|
+
|
|
5
|
+
[<AutoOpen>]
|
|
6
|
+
module ValidationCE =
|
|
7
|
+
type ValidationBuilder() =
|
|
8
|
+
member inline _.Return(value: 'ok) : Validation<'ok, 'error> = Validation.ok value
|
|
9
|
+
|
|
10
|
+
member inline _.ReturnFrom(result: Validation<'ok, 'error>) : Validation<'ok, 'error> =
|
|
11
|
+
result
|
|
12
|
+
|
|
13
|
+
member inline _.Bind
|
|
14
|
+
(
|
|
15
|
+
result: Validation<'okInput, 'error>,
|
|
16
|
+
[<InlineIfLambda>] binder: 'okInput -> Validation<'okOutput, 'error>
|
|
17
|
+
) : Validation<'okOutput, 'error> =
|
|
18
|
+
Validation.bind binder result
|
|
19
|
+
|
|
20
|
+
member inline this.Zero() : Validation<unit, 'error> = this.Return()
|
|
21
|
+
|
|
22
|
+
member inline _.Delay
|
|
23
|
+
([<InlineIfLambda>] generator: unit -> Validation<'ok, 'error>)
|
|
24
|
+
: unit -> Validation<'ok, 'error> =
|
|
25
|
+
generator
|
|
26
|
+
|
|
27
|
+
member inline _.Run
|
|
28
|
+
([<InlineIfLambda>] generator: unit -> Validation<'ok, 'error>)
|
|
29
|
+
: Validation<'ok, 'error> =
|
|
30
|
+
generator ()
|
|
31
|
+
|
|
32
|
+
member inline this.Combine
|
|
33
|
+
(
|
|
34
|
+
result: Validation<unit, 'error>,
|
|
35
|
+
[<InlineIfLambda>] binder: unit -> Validation<'ok, 'error>
|
|
36
|
+
) : Validation<'ok, 'error> =
|
|
37
|
+
this.Bind(result, binder)
|
|
38
|
+
|
|
39
|
+
member inline this.TryWith
|
|
40
|
+
(
|
|
41
|
+
[<InlineIfLambda>] generator: unit -> Validation<'ok, 'error>,
|
|
42
|
+
[<InlineIfLambda>] handler: exn -> Validation<'ok, 'error>
|
|
43
|
+
) : Validation<'ok, 'error> =
|
|
44
|
+
try
|
|
45
|
+
this.Run generator
|
|
46
|
+
with e ->
|
|
47
|
+
handler e
|
|
48
|
+
|
|
49
|
+
member inline this.TryFinally
|
|
50
|
+
(
|
|
51
|
+
[<InlineIfLambda>] generator: unit -> Validation<'ok, 'error>,
|
|
52
|
+
[<InlineIfLambda>] compensation: unit -> unit
|
|
53
|
+
) : Validation<'ok, 'error> =
|
|
54
|
+
try
|
|
55
|
+
this.Run generator
|
|
56
|
+
finally
|
|
57
|
+
compensation ()
|
|
58
|
+
|
|
59
|
+
member inline this.Using
|
|
60
|
+
(
|
|
61
|
+
resource: 'disposable :> IDisposableNull,
|
|
62
|
+
[<InlineIfLambda>] binder: 'disposable -> Validation<'okOutput, 'error>
|
|
63
|
+
) : Validation<'okOutput, 'error> =
|
|
64
|
+
this.TryFinally(
|
|
65
|
+
(fun () -> binder resource),
|
|
66
|
+
(fun () ->
|
|
67
|
+
if not (obj.ReferenceEquals(resource, null)) then
|
|
68
|
+
resource.Dispose()
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
member inline this.While
|
|
73
|
+
(
|
|
74
|
+
[<InlineIfLambda>] guard: unit -> bool,
|
|
75
|
+
[<InlineIfLambda>] generator: unit -> Validation<unit, 'error>
|
|
76
|
+
) : Validation<unit, 'error> =
|
|
77
|
+
let mutable doContinue = true
|
|
78
|
+
let mutable result = Ok()
|
|
79
|
+
|
|
80
|
+
while doContinue
|
|
81
|
+
&& guard () do
|
|
82
|
+
match generator () with
|
|
83
|
+
| Ok() -> ()
|
|
84
|
+
| Error e ->
|
|
85
|
+
doContinue <- false
|
|
86
|
+
result <- Error e
|
|
87
|
+
|
|
88
|
+
result
|
|
89
|
+
|
|
90
|
+
member inline this.For
|
|
91
|
+
(sequence: #seq<'ok>, [<InlineIfLambda>] binder: 'ok -> Validation<unit, 'error>)
|
|
92
|
+
: Validation<unit, 'error> =
|
|
93
|
+
this.Using(
|
|
94
|
+
sequence.GetEnumerator(),
|
|
95
|
+
fun enum -> this.While(enum.MoveNext, this.Delay(fun () -> binder enum.Current))
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
member inline _.BindReturn
|
|
99
|
+
(input: Validation<'okInput, 'error>, [<InlineIfLambda>] mapper: 'okInput -> 'okOutput)
|
|
100
|
+
: Validation<'okOutput, 'error> =
|
|
101
|
+
Validation.map mapper input
|
|
102
|
+
|
|
103
|
+
member inline _.MergeSources
|
|
104
|
+
(left: Validation<'left, 'error>, right: Validation<'right, 'error>)
|
|
105
|
+
: Validation<'left * 'right, 'error> =
|
|
106
|
+
Validation.zip left right
|
|
107
|
+
|
|
108
|
+
/// <summary>
|
|
109
|
+
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
|
|
110
|
+
///
|
|
111
|
+
/// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder
|
|
112
|
+
/// </summary>
|
|
113
|
+
/// <param name="result"></param>
|
|
114
|
+
/// <returns></returns>
|
|
115
|
+
member inline _.Source(result: Validation<'ok, 'error>) : Validation<'ok, 'error> = result
|
|
116
|
+
|
|
117
|
+
let validation = ValidationBuilder()
|
|
118
|
+
|
|
119
|
+
[<AutoOpen>]
|
|
120
|
+
module ValidationCEExtensions =
|
|
121
|
+
|
|
122
|
+
// Having members as extensions gives them lower priority in
|
|
123
|
+
// overload resolution and allows skipping more type annotations.
|
|
124
|
+
type ValidationBuilder with
|
|
125
|
+
|
|
126
|
+
/// <summary>
|
|
127
|
+
/// Needed to allow `for..in` and `for..do` functionality
|
|
128
|
+
/// </summary>
|
|
129
|
+
member inline _.Source(s: #seq<_>) : #seq<_> = s
|
|
130
|
+
|
|
131
|
+
/// <summary>
|
|
132
|
+
/// Method lets us transform data types into our internal representation.
|
|
133
|
+
/// </summary>
|
|
134
|
+
member inline _.Source(s: Result<'ok, 'error>) : Validation<'ok, 'error> =
|
|
135
|
+
Validation.ofResult s
|
|
136
|
+
|
|
137
|
+
/// <summary>
|
|
138
|
+
/// Method lets us transform data types into our internal representation.
|
|
139
|
+
/// </summary>
|
|
140
|
+
/// <returns></returns>
|
|
141
|
+
member inline _.Source(choice: Choice<'ok, 'error>) : Validation<'ok, 'error> =
|
|
142
|
+
Validation.ofChoice choice
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import { class_type } from "../fable-library-js.5.17.2/Reflection.js";
|
|
3
|
+
|
|
4
|
+
export class ValidationCE_ValidationBuilder {
|
|
5
|
+
constructor() {
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function ValidationCE_ValidationBuilder_$reflection() {
|
|
10
|
+
return class_type("FsToolkit.ErrorHandling.ValidationCE.ValidationBuilder", undefined, ValidationCE_ValidationBuilder);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ValidationCE_ValidationBuilder_$ctor() {
|
|
14
|
+
return new ValidationCE_ValidationBuilder();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ValidationCE_validation = ValidationCE_ValidationBuilder_$ctor();
|
|
18
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
namespace FsToolkit.ErrorHandling.Operator.Validation
|
|
2
|
+
|
|
3
|
+
open FsToolkit.ErrorHandling
|
|
4
|
+
|
|
5
|
+
[<AutoOpen>]
|
|
6
|
+
module Validation =
|
|
7
|
+
let inline (<!>)
|
|
8
|
+
([<InlineIfLambda>] mapper: 'okInput -> 'okOutput)
|
|
9
|
+
(input: Validation<'okInput, 'error>)
|
|
10
|
+
: Validation<'okOutput, 'error> =
|
|
11
|
+
Result.map mapper input
|
|
12
|
+
|
|
13
|
+
let inline (<!^>)
|
|
14
|
+
([<InlineIfLambda>] mapper: 'okInput -> 'okOutput)
|
|
15
|
+
(input: Result<'okInput, 'error>)
|
|
16
|
+
: Validation<'okOutput, 'error> =
|
|
17
|
+
Result.map mapper (Validation.ofResult (input))
|
|
18
|
+
|
|
19
|
+
let inline (<*>)
|
|
20
|
+
(applier: Validation<('okInput -> 'okOutput), 'error>)
|
|
21
|
+
(input: Validation<'okInput, 'error>)
|
|
22
|
+
: Validation<'okOutput, 'error> =
|
|
23
|
+
Validation.apply applier input
|
|
24
|
+
|
|
25
|
+
let inline (<*^>)
|
|
26
|
+
(applier: Validation<('okInput -> 'okOutput), 'error>)
|
|
27
|
+
(input: Result<'okInput, 'error>)
|
|
28
|
+
: Validation<'okOutput, 'error> =
|
|
29
|
+
Validation.apply applier (Validation.ofResult input)
|
|
30
|
+
|
|
31
|
+
let inline (>>=)
|
|
32
|
+
(input: Validation<'okInput, 'error>)
|
|
33
|
+
([<InlineIfLambda>] binder: 'okInput -> Validation<'okOutput, 'error>)
|
|
34
|
+
: Validation<'okOutput, 'error> =
|
|
35
|
+
Validation.bind binder input
|