@glutinum/cli 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/Glutinum.Converter/FsharpAST.js +57 -17
  2. package/dist/Glutinum.Converter/FsharpAST.js.map +1 -1
  3. package/dist/Glutinum.Converter/Generate.js +5 -7
  4. package/dist/Glutinum.Converter/Generate.js.map +1 -1
  5. package/dist/Glutinum.Converter/GlueAST.js +71 -13
  6. package/dist/Glutinum.Converter/GlueAST.js.map +1 -1
  7. package/dist/Glutinum.Converter/Log.js +5 -5
  8. package/dist/Glutinum.Converter/Log.js.map +1 -1
  9. package/dist/Glutinum.Converter/Merge.js +7 -7
  10. package/dist/Glutinum.Converter/Printer.js +153 -73
  11. package/dist/Glutinum.Converter/Printer.js.map +1 -1
  12. package/dist/Glutinum.Converter/Reader/Declaration.js +20 -19
  13. package/dist/Glutinum.Converter/Reader/Declaration.js.map +1 -1
  14. package/dist/Glutinum.Converter/Reader/EnumDeclaration.js +4 -3
  15. package/dist/Glutinum.Converter/Reader/EnumDeclaration.js.map +1 -1
  16. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +2 -2
  17. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js.map +1 -1
  18. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +5 -6
  19. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js.map +1 -1
  20. package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +42 -0
  21. package/dist/Glutinum.Converter/Reader/MappedTypeNode.js.map +1 -0
  22. package/dist/Glutinum.Converter/Reader/Node.js +8 -5
  23. package/dist/Glutinum.Converter/Reader/Node.js.map +1 -1
  24. package/dist/Glutinum.Converter/Reader/Parameters.js +7 -4
  25. package/dist/Glutinum.Converter/Reader/Parameters.js.map +1 -1
  26. package/dist/Glutinum.Converter/Reader/Report.js +35 -0
  27. package/dist/Glutinum.Converter/Reader/Report.js.map +1 -0
  28. package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -0
  29. package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js.map +1 -1
  30. package/dist/Glutinum.Converter/Reader/TypeNode.js +97 -27
  31. package/dist/Glutinum.Converter/Reader/TypeNode.js.map +1 -1
  32. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +31 -26
  33. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js.map +1 -1
  34. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +127 -0
  35. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js.map +1 -0
  36. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +7 -2
  37. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js.map +1 -1
  38. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +6 -9
  39. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js.map +1 -1
  40. package/dist/Glutinum.Converter/Reader/Utils.js +1 -11
  41. package/dist/Glutinum.Converter/Reader/Utils.js.map +1 -1
  42. package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -2
  43. package/dist/Glutinum.Converter/Reader/VariableStatement.js.map +1 -1
  44. package/dist/Glutinum.Converter/Transform.js +327 -154
  45. package/dist/Glutinum.Converter/Transform.js.map +1 -1
  46. package/dist/Glutinum.Converter/TypeScript.Extensions.js +735 -0
  47. package/dist/Glutinum.Converter/TypeScript.Extensions.js.map +1 -0
  48. package/dist/Glutinum.Converter/Utils/Naming.js +6 -2
  49. package/dist/Glutinum.Converter/Utils/Naming.js.map +1 -1
  50. package/dist/Program.js +2 -2
  51. package/dist/Program.js.map +1 -1
  52. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AssemblyInfo.fs +19 -0
  53. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Async.fs +207 -0
  54. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Async.fs.js +127 -0
  55. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Async.fs.js.map +1 -0
  56. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOption.fs +81 -0
  57. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOptionCE.fs +183 -0
  58. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOptionCE.fs.js +37 -0
  59. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOptionCE.fs.js.map +1 -0
  60. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOptionOp.fs +24 -0
  61. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResult.fs +439 -0
  62. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultCE.fs +217 -0
  63. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultCE.fs.js +18 -0
  64. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultCE.fs.js.map +1 -0
  65. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOp.fs +24 -0
  66. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOption.fs +75 -0
  67. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOption.fs.js +26 -0
  68. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOption.fs.js.map +1 -0
  69. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOptionCE.fs +238 -0
  70. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOptionCE.fs.js +18 -0
  71. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOptionCE.fs.js.map +1 -0
  72. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOptionOp.fs +24 -0
  73. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidation.fs +190 -0
  74. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidationCE.fs +194 -0
  75. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidationCE.fs.js +18 -0
  76. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidationCE.fs.js.map +1 -0
  77. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidationOp.fs +35 -0
  78. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/FsToolkit.ErrorHandling.fableproj +51 -0
  79. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/List.fs +218 -0
  80. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/List.fs.js +358 -0
  81. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/List.fs.js.map +1 -0
  82. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Option.fs +331 -0
  83. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/OptionCE.fs +186 -0
  84. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/OptionCE.fs.js +18 -0
  85. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/OptionCE.fs.js.map +1 -0
  86. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/OptionOp.fs +21 -0
  87. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Result.fs +644 -0
  88. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Result.fs.js +45 -0
  89. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Result.fs.js.map +1 -0
  90. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultCE.fs +155 -0
  91. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultCE.fs.js +23 -0
  92. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultCE.fs.js.map +1 -0
  93. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOp.fs +45 -0
  94. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOption.fs +201 -0
  95. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOption.fs.js +65 -0
  96. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOption.fs.js.map +1 -0
  97. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOptionCE.fs +146 -0
  98. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOptionCE.fs.js +18 -0
  99. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOptionCE.fs.js.map +1 -0
  100. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOptionOp.fs +57 -0
  101. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Seq.fs +19 -0
  102. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Seq.fs.js +31 -0
  103. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Seq.fs.js.map +1 -0
  104. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Shims.fs +22 -0
  105. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Shims.fs.js +18 -0
  106. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Shims.fs.js.map +1 -0
  107. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Validation.fs +172 -0
  108. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValidationCE.fs +148 -0
  109. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValidationCE.fs.js +18 -0
  110. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValidationCE.fs.js.map +1 -0
  111. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValidationOp.fs +35 -0
  112. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValueOption.fs +151 -0
  113. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValueOptionCE.fs +165 -0
  114. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Debug/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  115. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Debug/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  116. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.fs +3 -0
  117. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Release/netstandard2.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  118. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Release/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  119. package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Release/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  120. package/dist/fable_modules/project_cracked.json +1 -1
  121. package/package.json +3 -2
  122. package/src/Glutinum.Converter/js/bootstrap.js +16 -0
@@ -0,0 +1,183 @@
1
+ namespace FsToolkit.ErrorHandling
2
+
3
+ open System.Threading.Tasks
4
+ open System
5
+
6
+ [<AutoOpen>]
7
+ module AsyncOptionCE =
8
+ type AsyncOptionBuilder() =
9
+
10
+ member inline _.Return(value: 'value) : Async<'value option> = AsyncOption.retn value
11
+
12
+ member inline _.ReturnFrom(value: Async<'value option>) : Async<'value option> = value
13
+
14
+ member inline _.Zero() : Async<unit option> =
15
+ option.Zero()
16
+ |> async.Return
17
+
18
+ member inline _.Bind
19
+ (
20
+ input: Async<'input option>,
21
+ [<InlineIfLambda>] binder: 'input -> Async<'output option>
22
+ ) : Async<'output option> =
23
+ AsyncOption.bind binder input
24
+
25
+ member inline _.Delay(generator: unit -> Async<'value option>) : Async<'value option> =
26
+ async.Delay generator
27
+
28
+ member inline this.Combine
29
+ (
30
+ computation1: Async<_ option>,
31
+ computation2: Async<_ option>
32
+ ) : Async<_ option> =
33
+ this.Bind(computation1, (fun () -> computation2))
34
+
35
+ member inline _.TryWith
36
+ (
37
+ computation: Async<'value option>,
38
+ [<InlineIfLambda>] handler: System.Exception -> Async<'value option>
39
+ ) : Async<_ option> =
40
+ async.TryWith(computation, handler)
41
+
42
+ member inline _.TryFinally
43
+ (
44
+ computation: Async<'value option>,
45
+ [<InlineIfLambda>] compensation: unit -> unit
46
+ ) : Async<'value option> =
47
+ async.TryFinally(computation, compensation)
48
+
49
+
50
+ #if NETSTANDARD2_1
51
+
52
+ member inline _.TryFinallyAsync
53
+ (
54
+ computation: Async<'value option>,
55
+ [<InlineIfLambda>] compensation: unit -> ValueTask
56
+ ) : Async<'value option> =
57
+ let compensation =
58
+ async {
59
+ let vTask = compensation ()
60
+
61
+ if vTask.IsCompletedSuccessfully then
62
+ return ()
63
+ else
64
+ return!
65
+ vTask.AsTask()
66
+ |> Async.AwaitTask
67
+ }
68
+
69
+ Async.TryFinallyAsync(computation, compensation)
70
+
71
+
72
+ member inline this.Using
73
+ (
74
+ resource: 'ok :> IAsyncDisposable,
75
+ [<InlineIfLambda>] binder: 'ok -> Async<'value option>
76
+ ) : Async<'value option> =
77
+ this.TryFinallyAsync(
78
+ binder resource,
79
+ (fun () ->
80
+ if not (isNull (box resource)) then
81
+ resource.DisposeAsync()
82
+ else
83
+ ValueTask()
84
+ )
85
+ )
86
+ #endif
87
+
88
+ member this.While
89
+ (
90
+ guard: unit -> bool,
91
+ computation: Async<unit option>
92
+ ) : Async<unit option> =
93
+ if not (guard ()) then
94
+ this.Zero()
95
+ else
96
+ this.Bind(computation, (fun () -> this.While(guard, computation)))
97
+
98
+
99
+ /// <summary>
100
+ /// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
101
+ ///
102
+ /// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder
103
+ /// </summary>
104
+ member inline _.Source(async: Async<'value option>) : Async<'value option> = async
105
+
106
+ #if !FABLE_COMPILER
107
+ /// <summary>
108
+ /// Method lets us transform data types into our internal representation.
109
+ /// </summary>
110
+ member inline _.Source(task: Task<'value option>) : Async<'value option> =
111
+ task
112
+ |> Async.AwaitTask
113
+
114
+ #endif
115
+
116
+ let asyncOption = AsyncOptionBuilder()
117
+
118
+
119
+ [<AutoOpen>]
120
+ // Having members as extensions gives them lower priority in
121
+ // overload resolution and allows skipping more type annotations.
122
+ module AsyncOptionCEExtensions =
123
+
124
+ type AsyncOptionBuilder 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(r: 'value option) : Async<option<'value>> = Async.singleton r
135
+
136
+ /// <summary>
137
+ /// Method lets us transform data types into our internal representation.
138
+ /// </summary>
139
+ member inline _.Source(a: Async<'value>) : Async<option<'value>> =
140
+ a
141
+ |> Async.map Some
142
+
143
+ member inline this.Using
144
+ (
145
+ resource: 'disposable :> IDisposable,
146
+ [<InlineIfLambda>] binder: 'disposable -> Async<'output option>
147
+ ) : Async<'output option> =
148
+ this.TryFinally(
149
+ (binder resource),
150
+ (fun () ->
151
+ if not (obj.ReferenceEquals(resource, null)) then
152
+ resource.Dispose()
153
+ )
154
+ )
155
+
156
+ member inline this.For
157
+ (
158
+ sequence: #seq<'input>,
159
+ binder: 'input -> Async<unit option>
160
+ ) : Async<unit option> =
161
+ this.Using(
162
+ sequence.GetEnumerator(),
163
+ fun enum -> this.While(enum.MoveNext, this.Delay(fun () -> binder enum.Current))
164
+ )
165
+
166
+
167
+ #if !FABLE_COMPILER
168
+ /// <summary>
169
+ /// Method lets us transform data types into our internal representation.
170
+ /// </summary>
171
+ member inline _.Source(a: Task<'value>) : Async<option<'value>> =
172
+ a
173
+ |> Async.AwaitTask
174
+ |> Async.map Some
175
+
176
+ /// <summary>
177
+ /// Method lets us transform data types into our internal representation.
178
+ /// </summary>
179
+ member inline _.Source(a: Task) : Async<option<unit>> =
180
+ a
181
+ |> Async.AwaitTask
182
+ |> Async.map Some
183
+ #endif
@@ -0,0 +1,37 @@
1
+ import { class_type } from "../fable-library-js.4.14.0/Reflection.js";
2
+ import { singleton } from "../fable-library-js.4.14.0/AsyncBuilder.js";
3
+ import { value as value_2, some } from "../fable-library-js.4.14.0/Option.js";
4
+
5
+ export class AsyncOptionCE_AsyncOptionBuilder {
6
+ constructor() {
7
+ }
8
+ }
9
+
10
+ export function AsyncOptionCE_AsyncOptionBuilder_$reflection() {
11
+ return class_type("FsToolkit.ErrorHandling.AsyncOptionCE.AsyncOptionBuilder", void 0, AsyncOptionCE_AsyncOptionBuilder);
12
+ }
13
+
14
+ export function AsyncOptionCE_AsyncOptionBuilder_$ctor() {
15
+ return new AsyncOptionCE_AsyncOptionBuilder();
16
+ }
17
+
18
+ export function AsyncOptionCE_AsyncOptionBuilder__While_78DDE493(this$, guard, computation) {
19
+ if (!guard()) {
20
+ return singleton.Return(some(void 0));
21
+ }
22
+ else {
23
+ return singleton.Bind(computation, (x_1) => {
24
+ if (x_1 == null) {
25
+ return singleton.Return(void 0);
26
+ }
27
+ else {
28
+ const unitVar_2 = value_2(x_1);
29
+ return AsyncOptionCE_AsyncOptionBuilder__While_78DDE493(this$, guard, computation);
30
+ }
31
+ });
32
+ }
33
+ }
34
+
35
+ export const AsyncOptionCE_asyncOption = AsyncOptionCE_AsyncOptionBuilder_$ctor();
36
+
37
+ //# sourceMappingURL=AsyncOptionCE.fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["./AsyncOptionCE.fs","./OptionCE.fs","./Async.fs","./AsyncOption.fs"],"names":["guard","computation","x","unitVar0","While","this","\u0060\u0060.ctor\u0060\u0060"],"mappings":";;;;;;;;;;;;;;;;;;AA4FY,QAAG,CAAK,AAAAA;AA7EL,eAAA,iBCR6C,KAmBC;;;ACUrD,eAAA,eF2DkBC;AG9EJ,gBAAA,AAAAC;ADFX,uBAAA,iBCI\u002BB;;;AH4EEC,0CG7EhBD;AH6EsB,uBAAA,AAAAE,iDAAAC,OAAWL,OAAOC;;;;;;yCAoB9C,AAAAK","file":null,"sourcesContent":null,"sourceRoot":null}
@@ -0,0 +1,24 @@
1
+ namespace FsToolkit.ErrorHandling.Operator.AsyncOption
2
+
3
+ open FsToolkit.ErrorHandling
4
+
5
+ [<AutoOpen>]
6
+ module AsyncOption =
7
+
8
+ let inline (<!>)
9
+ (([<InlineIfLambda>] mapper: 'input -> 'output))
10
+ (input: Async<'input option>)
11
+ : Async<'output option> =
12
+ AsyncOption.map mapper input
13
+
14
+ let inline (<*>)
15
+ (applier: Async<('input -> 'output) option>)
16
+ (input: Async<'input option>)
17
+ : Async<'output option> =
18
+ AsyncOption.apply applier input
19
+
20
+ let inline (>>=)
21
+ (input: Async<'input option>)
22
+ ([<InlineIfLambda>] binder: 'input -> Async<'output option>)
23
+ : Async<'output option> =
24
+ AsyncOption.bind binder input
@@ -0,0 +1,439 @@
1
+ namespace FsToolkit.ErrorHandling
2
+
3
+ open System.Threading.Tasks
4
+
5
+ [<RequireQualifiedAccess>]
6
+ module AsyncResult =
7
+
8
+
9
+ let inline retn (value: 'ok) : Async<Result<'ok, 'error>> =
10
+ Ok value
11
+ |> Async.singleton
12
+
13
+ let inline ok (value: 'ok) : Async<Result<'ok, 'error>> = retn value
14
+
15
+ let inline returnError (error: 'error) : Async<Result<'ok, 'error>> =
16
+ Error error
17
+ |> Async.singleton
18
+
19
+ let inline error (error: 'error) : Async<Result<'ok, 'error>> = returnError error
20
+
21
+ let inline map
22
+ ([<InlineIfLambda>] mapper: 'input -> 'output)
23
+ (input: Async<Result<'input, 'error>>)
24
+ : Async<Result<'output, 'error>> =
25
+ Async.map (Result.map mapper) input
26
+
27
+ let inline mapError
28
+ ([<InlineIfLambda>] mapper: 'inputError -> 'outputError)
29
+ (input: Async<Result<'ok, 'inputError>>)
30
+ : Async<Result<'ok, 'outputError>> =
31
+ Async.map (Result.mapError mapper) input
32
+
33
+ let inline bind
34
+ ([<InlineIfLambda>] binder: 'input -> Async<Result<'output, 'error>>)
35
+ (input: Async<Result<'input, 'error>>)
36
+ : Async<Result<'output, 'error>> =
37
+ Async.bind (Result.either binder returnError) input
38
+
39
+ let inline foldResult
40
+ ([<InlineIfLambda>] onSuccess: 'input -> 'output)
41
+ ([<InlineIfLambda>] onError: 'inputError -> 'output)
42
+ (input: Async<Result<'input, 'inputError>>)
43
+ : Async<'output> =
44
+ Async.map (Result.either onSuccess onError) input
45
+
46
+ let inline eitherMap ([<InlineIfLambda>] onSuccess) ([<InlineIfLambda>] onError) input =
47
+ Async.map (Result.eitherMap onSuccess onError) input
48
+
49
+ #if !FABLE_COMPILER
50
+
51
+ let inline ofTask (aTask: Task<'ok>) : Async<Result<'ok, exn>> =
52
+ async.Delay(fun () ->
53
+ aTask
54
+ |> Async.AwaitTask
55
+ |> Async.Catch
56
+ |> Async.map Result.ofChoice
57
+ )
58
+
59
+ let inline ofTaskAction (aTask: Task) : Async<Result<unit, exn>> =
60
+ async.Delay(fun () ->
61
+ aTask
62
+ |> Async.AwaitTask
63
+ |> Async.Catch
64
+ |> Async.map Result.ofChoice
65
+ )
66
+
67
+ #endif
68
+
69
+
70
+ let inline map2
71
+ ([<InlineIfLambda>] mapper: 'input1 -> 'input2 -> 'output)
72
+ (input1: Async<Result<'input1, 'error>>)
73
+ (input2: Async<Result<'input2, 'error>>)
74
+ : Async<Result<'output, 'error>> =
75
+ Async.map2 (Result.map2 mapper) input1 input2
76
+
77
+ let inline map3
78
+ ([<InlineIfLambda>] mapper: 'input1 -> 'input2 -> 'input3 -> 'output)
79
+ (input1: Async<Result<'input1, 'error>>)
80
+ (input2: Async<Result<'input2, 'error>>)
81
+ (input3: Async<Result<'input3, 'error>>)
82
+ : Async<Result<'output, 'error>> =
83
+ Async.map3 (Result.map3 mapper) input1 input2 input3
84
+
85
+ let inline apply
86
+ (applier: Async<Result<'input -> 'output, 'error>>)
87
+ (input: Async<Result<'input, 'error>>)
88
+ : Async<Result<'output, 'error>> =
89
+ map2 (fun f x -> f x) applier input
90
+
91
+
92
+ /// <summary>
93
+ /// Returns <paramref name="input"/> if it is <c>Ok</c>, otherwise returns <paramref name="ifError"/>
94
+ /// </summary>
95
+ /// <param name="ifError">The value to use if <paramref name="input"/> is <c>Error</c></param>
96
+ /// <param name="input">The input result.</param>
97
+ /// <remarks>
98
+ /// </remarks>
99
+ /// <example>
100
+ /// <code>
101
+ /// AsyncResult.error "First" |> AsyncResult.orElse (AsyncResult.error "Second") // evaluates to Error ("Second")
102
+ /// AsyncResult.error "First" |> AsyncResult.orElse (AsyncResult.ok "Second") // evaluates to Ok ("Second")
103
+ /// AsyncResult.ok "First" |> AsyncResult.orElse (AsyncResult.error "Second") // evaluates to Ok ("First")
104
+ /// AsyncResult.ok "First" |> AsyncResult.orElse (AsyncResult.ok "Second") // evaluates to Ok ("First")
105
+ /// </code>
106
+ /// </example>
107
+ /// <returns>
108
+ /// The result if the result is Ok, else returns <paramref name="ifError"/>.
109
+ /// </returns>
110
+ let inline orElse
111
+ (ifError: Async<Result<'ok, 'errorOutput>>)
112
+ (input: Async<Result<'ok, 'errorInput>>)
113
+ : Async<Result<'ok, 'errorOutput>> =
114
+ Async.bind (Result.either ok (fun _ -> ifError)) input
115
+
116
+ /// <summary>
117
+ /// Returns <paramref name="input"/> if it is <c>Ok</c>, otherwise executes <paramref name="ifErrorFunc"/> and returns the result.
118
+ /// </summary>
119
+ /// <param name="ifErrorFunc">A function that provides an alternate result when evaluated.</param>
120
+ /// <param name="input">The input result.</param>
121
+ /// <remarks>
122
+ /// <paramref name="ifErrorFunc"/> is not executed unless <paramref name="input"/> is an <c>Error</c>.
123
+ /// </remarks>
124
+ /// <example>
125
+ /// <code>
126
+ /// AsyncResult.error "First" |> AsyncResult.orElseWith (fun _ -> AsyncResult.error "Second") // evaluates to Error ("Second")
127
+ /// AsyncResult.error "First" |> AsyncResult.orElseWith (fun _ -> AsyncResult.ok "Second") // evaluates to Ok ("Second")
128
+ /// AsyncResult.ok "First" |> AsyncResult.orElseWith (fun _ -> AsyncResult.error "Second") // evaluates to Ok ("First")
129
+ /// AsyncResult.ok "First" |> AsyncResult.orElseWith (fun _ -> AsyncResult.ok "Second") // evaluates to Ok ("First")
130
+ /// </code>
131
+ /// </example>
132
+ /// <returns>
133
+ /// The result if the result is Ok, else the result of executing <paramref name="ifErrorFunc"/>.
134
+ /// </returns>
135
+ let inline orElseWith
136
+ ([<InlineIfLambda>] ifErrorFunc: 'errorInput -> Async<Result<'ok, 'errorOutput>>)
137
+ (input: Async<Result<'ok, 'errorInput>>)
138
+ : Async<Result<'ok, 'errorOutput>> =
139
+ Async.bind (Result.either ok ifErrorFunc) input
140
+
141
+ /// Replaces the wrapped value with unit
142
+ let inline ignore<'ok, 'error>
143
+ (value: Async<Result<'ok, 'error>>)
144
+ : Async<Result<unit, 'error>> =
145
+ value
146
+ |> map ignore<'ok>
147
+
148
+ /// Returns the specified error if the async-wrapped value is false.
149
+ let inline requireTrue (error: 'error) (value: Async<bool>) : Async<Result<unit, 'error>> =
150
+ value
151
+ |> Async.map (Result.requireTrue error)
152
+
153
+ /// Returns the specified error if the async-wrapped value is true.
154
+ let inline requireFalse (error: 'error) (value: Async<bool>) : Async<Result<unit, 'error>> =
155
+ value
156
+ |> Async.map (Result.requireFalse error)
157
+
158
+ // Converts an async-wrapped Option to a Result, using the given error if None.
159
+ let inline requireSome (error: 'error) (value: Async<'ok option>) : Async<Result<'ok, 'error>> =
160
+ value
161
+ |> Async.map (Result.requireSome error)
162
+
163
+ // Converts an async-wrapped Option to a Result, using the given error if Some.
164
+ let inline requireNone
165
+ (error: 'error)
166
+ (value: Async<'ok option>)
167
+ : Async<Result<unit, 'error>> =
168
+ value
169
+ |> Async.map (Result.requireNone error)
170
+
171
+ // Converts an async-wrapped ValueOption to a Result, using the given error if ValueNone.
172
+ let inline requireValueSome
173
+ (error: 'error)
174
+ (value: Async<'ok voption>)
175
+ : Async<Result<'ok, 'error>> =
176
+ value
177
+ |> Async.map (Result.requireValueSome error)
178
+
179
+ // Converts an async-wrapped ValueOption to a Result, using the given error if ValueSome.
180
+ let inline requireValueNone
181
+ (error: 'error)
182
+ (value: Async<'ok voption>)
183
+ : Async<Result<unit, 'error>> =
184
+ value
185
+ |> Async.map (Result.requireValueNone error)
186
+
187
+ /// Returns Ok if the async-wrapped value and the provided value are equal, or the specified error if not.
188
+ let inline requireEqual
189
+ (value1: 'value)
190
+ (value2: Async<'value>)
191
+ (error: 'error)
192
+ : Async<Result<unit, 'error>> =
193
+ value2
194
+ |> Async.map (fun x2' -> Result.requireEqual value1 x2' error)
195
+
196
+ /// Returns Ok if the two values are equal, or the specified error if not.
197
+ let inline requireEqualTo
198
+ (other: 'value)
199
+ (error: 'error)
200
+ (this: Async<'value>)
201
+ : Async<Result<unit, 'error>> =
202
+ this
203
+ |> Async.map (Result.requireEqualTo other error)
204
+
205
+ /// Returns Ok if the async-wrapped sequence is empty, or the specified error if not.
206
+ let inline requireEmpty
207
+ (error: 'error)
208
+ (values: Async<#seq<'ok>>)
209
+ : Async<Result<unit, 'error>> =
210
+ values
211
+ |> Async.map (Result.requireEmpty error)
212
+
213
+ /// Returns Ok if the async-wrapped sequence is not-empty, or the specified error if not.
214
+ let inline requireNotEmpty
215
+ (error: 'error)
216
+ (values: Async<#seq<'ok>>)
217
+ : Async<Result<unit, 'error>> =
218
+ values
219
+ |> Async.map (Result.requireNotEmpty error)
220
+
221
+ /// Returns the first item of the async-wrapped sequence if it exists, or the specified
222
+ /// error if the sequence is empty
223
+ let inline requireHead (error: 'error) (values: Async<#seq<'ok>>) : Async<Result<'ok, 'error>> =
224
+ values
225
+ |> Async.map (Result.requireHead error)
226
+
227
+ /// Replaces an error value of an async-wrapped result with a custom error
228
+ /// value.
229
+ let inline setError
230
+ (error: 'errorOutput)
231
+ (asyncResult: Async<Result<'ok, 'errorInput>>)
232
+ : Async<Result<'ok, 'errorOutput>> =
233
+ asyncResult
234
+ |> Async.map (Result.setError error)
235
+
236
+ /// Replaces a unit error value of an async-wrapped result with a custom
237
+ /// error value. Safer than setError since you're not losing any information.
238
+ let inline withError
239
+ (error: 'errorOutput)
240
+ (asyncResult: Async<Result<'ok, unit>>)
241
+ : Async<Result<'ok, 'errorOutput>> =
242
+ asyncResult
243
+ |> Async.map (Result.withError error)
244
+
245
+ /// Extracts the contained value of an async-wrapped result if Ok, otherwise
246
+ /// uses ifError.
247
+ let inline defaultValue (ifError: 'ok) (asyncResult: Async<Result<'ok, 'error>>) : Async<'ok> =
248
+ asyncResult
249
+ |> Async.map (Result.defaultValue ifError)
250
+
251
+ /// Extracts the contained value of an async-wrapped result if Error, otherwise
252
+ /// uses ifOk.
253
+ let inline defaultError
254
+ (ifOk: 'error)
255
+ (asyncResult: Async<Result<'ok, 'error>>)
256
+ : Async<'error> =
257
+ asyncResult
258
+ |> Async.map (Result.defaultError ifOk)
259
+
260
+ /// Extracts the contained value of an async-wrapped result if Ok, otherwise
261
+ /// evaluates ifErrorThunk and uses the result.
262
+ let inline defaultWith
263
+ ([<InlineIfLambda>] ifErrorThunk: 'error -> 'ok)
264
+ (asyncResult: Async<Result<'ok, 'error>>)
265
+ : Async<'ok> =
266
+ asyncResult
267
+ |> Async.map (Result.defaultWith ifErrorThunk)
268
+
269
+ /// Same as defaultValue for a result where the Ok value is unit. The name
270
+ /// describes better what is actually happening in this case.
271
+ let inline ignoreError<'error> (result: Async<Result<unit, 'error>>) : Async<unit> =
272
+ defaultValue () result
273
+
274
+ /// If the async-wrapped result is Ok, executes the function on the Ok value.
275
+ /// Passes through the input value.
276
+ let inline tee
277
+ ([<InlineIfLambda>] inspector: 'ok -> unit)
278
+ (asyncResult: Async<Result<'ok, 'error>>)
279
+ : Async<Result<'ok, 'error>> =
280
+ asyncResult
281
+ |> Async.map (Result.tee inspector)
282
+
283
+ /// If the async-wrapped result is Ok and the predicate returns true, executes
284
+ /// the function on the Ok value. Passes through the input value.
285
+ let inline teeIf
286
+ ([<InlineIfLambda>] predicate: 'ok -> bool)
287
+ ([<InlineIfLambda>] inspector: 'ok -> unit)
288
+ (asyncResult: Async<Result<'ok, 'error>>)
289
+ : Async<Result<'ok, 'error>> =
290
+ asyncResult
291
+ |> Async.map (Result.teeIf predicate inspector)
292
+
293
+ /// If the async-wrapped result is Error, executes the function on the Error
294
+ /// value. Passes through the input value.
295
+ let inline teeError
296
+ ([<InlineIfLambda>] teeFunction: 'error -> unit)
297
+ (asyncResult: Async<Result<'ok, 'error>>)
298
+ : Async<Result<'ok, 'error>> =
299
+ asyncResult
300
+ |> Async.map (Result.teeError teeFunction)
301
+
302
+ /// If the async-wrapped result is Error and the predicate returns true,
303
+ /// executes the function on the Error value. Passes through the input value.
304
+ let inline teeErrorIf
305
+ ([<InlineIfLambda>] predicate: 'error -> bool)
306
+ ([<InlineIfLambda>] teeFunction: 'error -> unit)
307
+ (asyncResult: Async<Result<'ok, 'error>>)
308
+ : Async<Result<'ok, 'error>> =
309
+ asyncResult
310
+ |> Async.map (Result.teeErrorIf predicate teeFunction)
311
+
312
+
313
+ /// Takes two results and returns a tuple of the pair
314
+ let inline zip
315
+ (left: Async<Result<'leftOk, 'error>>)
316
+ (right: Async<Result<'rightOk, 'error>>)
317
+ : Async<Result<'leftOk * 'rightOk, 'error>> =
318
+ Async.zip left right
319
+ |> Async.map (fun (r1, r2) -> Result.zip r1 r2)
320
+
321
+ /// Takes two results and returns a tuple of the error pair
322
+ let inline zipError
323
+ (left: Async<Result<'ok, 'leftError>>)
324
+ (right: Async<Result<'ok, 'rightError>>)
325
+ : Async<Result<'ok, 'leftError * 'rightError>> =
326
+ Async.zip left right
327
+ |> Async.map (fun (r1, r2) -> Result.zipError r1 r2)
328
+
329
+ /// Catches exceptions and maps them to the Error case using the provided function.
330
+ let inline catch
331
+ ([<InlineIfLambda>] exnMapper: exn -> 'error)
332
+ (input: Async<Result<'ok, 'error>>)
333
+ : Async<Result<'ok, 'error>> =
334
+ input
335
+ |> Async.Catch
336
+ |> Async.map (
337
+ function
338
+ | Choice1Of2(Ok v) -> Ok v
339
+ | Choice1Of2(Error err) -> Error err
340
+ | Choice2Of2 ex -> Error(exnMapper ex)
341
+ )
342
+
343
+ /// Lift Async to AsyncResult
344
+ let inline ofAsync (value: Async<'ok>) : Async<Result<'ok, 'error>> =
345
+ value
346
+ |> Async.map Ok
347
+
348
+ /// Lift Result to AsyncResult
349
+ let inline ofResult (x: Result<'ok, 'error>) : Async<Result<'ok, 'error>> =
350
+ x
351
+ |> Async.singleton
352
+
353
+ /// Bind the AsyncResult and requireSome on the inner option value.
354
+ let inline bindRequireSome error x =
355
+ x
356
+ |> bind (
357
+ Result.requireSome error
358
+ >> Async.singleton
359
+ )
360
+
361
+ /// Bind the AsyncResult and requireNone on the inner option value.
362
+ let inline bindRequireNone error x =
363
+ x
364
+ |> bind (
365
+ Result.requireNone error
366
+ >> Async.singleton
367
+ )
368
+
369
+ /// Bind the AsyncResult and requireValueSome on the inner voption value.
370
+ let inline bindRequireValueSome error x =
371
+ x
372
+ |> bind (
373
+ Result.requireValueSome error
374
+ >> Async.singleton
375
+ )
376
+
377
+ /// Bind the AsyncResult and requireValueNone on the inner voption value.
378
+ let inline bindRequireValueNone error x =
379
+ x
380
+ |> bind (
381
+ Result.requireValueNone error
382
+ >> Async.singleton
383
+ )
384
+
385
+ /// Bind the AsyncResult and requireTrue on the inner value.
386
+ let inline bindRequireTrue error x =
387
+ x
388
+ |> bind (
389
+ Result.requireTrue error
390
+ >> Async.singleton
391
+ )
392
+
393
+ /// Bind the AsyncResult and requireFalse on the inner value.
394
+ let inline bindRequireFalse error x =
395
+ x
396
+ |> bind (
397
+ Result.requireFalse error
398
+ >> Async.singleton
399
+ )
400
+
401
+ /// Bind the AsyncResult and requireNotNull on the inner value.
402
+ let inline bindRequireNotNull error x =
403
+ x
404
+ |> bind (
405
+ Result.requireNotNull error
406
+ >> Async.singleton
407
+ )
408
+
409
+ /// Bind the AsyncResult and requireEequal on the inner value.
410
+ let inline bindRequireEqual y error x =
411
+ x
412
+ |> bind (fun x ->
413
+ Result.requireEqual x y error
414
+ |> Async.singleton
415
+ )
416
+
417
+ /// Bind the AsyncResult and requireEmpty on the inner value.
418
+ let inline bindRequireEmpty error x =
419
+ x
420
+ |> bind (
421
+ Result.requireEmpty error
422
+ >> Async.singleton
423
+ )
424
+
425
+ /// Bind the AsyncResult and requireNotEmpty on the inner value.
426
+ let inline bindRequireNotEmpty error x =
427
+ x
428
+ |> bind (
429
+ Result.requireNotEmpty error
430
+ >> Async.singleton
431
+ )
432
+
433
+ /// Bind the AsyncResult and requireHead on the inner value
434
+ let inline bindRequireHead error x =
435
+ x
436
+ |> bind (
437
+ Result.requireHead error
438
+ >> Async.singleton
439
+ )