@glutinum/cli 0.14.0 → 0.14.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.
Files changed (144) hide show
  1. package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs +89 -0
  2. package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs.js +105 -0
  3. package/dist/fable_modules/Fable.Promise.3.2.1/Fable.Promise.fableproj +25 -0
  4. package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs +842 -0
  5. package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs.js +232 -0
  6. package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs +31 -0
  7. package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js +20 -0
  8. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs +235 -0
  9. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs.js +384 -0
  10. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AssemblyInfo.fs +19 -0
  11. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs +287 -0
  12. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs.js +128 -0
  13. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOption.fs +127 -0
  14. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs +174 -0
  15. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs.js +37 -0
  16. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionOp.fs +24 -0
  17. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResult.fs +483 -0
  18. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs +201 -0
  19. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs.js +18 -0
  20. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOp.fs +24 -0
  21. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs +87 -0
  22. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs.js +26 -0
  23. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs +236 -0
  24. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs.js +18 -0
  25. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionOp.fs +24 -0
  26. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidation.fs +185 -0
  27. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs +186 -0
  28. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs.js +18 -0
  29. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationOp.fs +35 -0
  30. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/FsToolkit.ErrorHandling.fableproj +69 -0
  31. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs +276 -0
  32. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs.js +364 -0
  33. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Nullness.fs +81 -0
  34. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Option.fs +462 -0
  35. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs +139 -0
  36. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs.js +48 -0
  37. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionOp.fs +21 -0
  38. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs +88 -0
  39. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs.js +30 -0
  40. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs +200 -0
  41. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs.js +18 -0
  42. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidation.fs +34 -0
  43. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs +244 -0
  44. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs.js +18 -0
  45. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs +731 -0
  46. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs.js +45 -0
  47. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs +140 -0
  48. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs.js +23 -0
  49. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOp.fs +45 -0
  50. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs +201 -0
  51. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs.js +65 -0
  52. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs +135 -0
  53. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs.js +18 -0
  54. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionOp.fs +57 -0
  55. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs +503 -0
  56. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs.js +295 -0
  57. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Validation.fs +167 -0
  58. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs +142 -0
  59. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs.js +18 -0
  60. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationOp.fs +35 -0
  61. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueOption.fs +148 -0
  62. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOption.fs +102 -0
  63. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionCE.fs +587 -0
  64. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionOp.fs +10 -0
  65. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  66. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  67. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.fs +3 -0
  68. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  69. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.fs +3 -0
  70. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  71. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  72. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  73. package/dist/fable_modules/fable-library-js.5.17.2/Array.js +1348 -0
  74. package/dist/fable_modules/fable-library-js.5.17.2/Async.js +163 -0
  75. package/dist/fable_modules/fable-library-js.5.17.2/AsyncBuilder.js +204 -0
  76. package/dist/fable_modules/fable-library-js.5.17.2/BigInt.js +307 -0
  77. package/dist/fable_modules/fable-library-js.5.17.2/BitConverter.js +138 -0
  78. package/dist/fable_modules/fable-library-js.5.17.2/Boolean.js +22 -0
  79. package/dist/fable_modules/fable-library-js.5.17.2/CHANGELOG.md +348 -0
  80. package/dist/fable_modules/fable-library-js.5.17.2/Char.js +202 -0
  81. package/dist/fable_modules/fable-library-js.5.17.2/Choice.js +184 -0
  82. package/dist/fable_modules/fable-library-js.5.17.2/CollectionUtil.js +182 -0
  83. package/dist/fable_modules/fable-library-js.5.17.2/ConditionalWeakTable.js +21 -0
  84. package/dist/fable_modules/fable-library-js.5.17.2/Date.js +834 -0
  85. package/dist/fable_modules/fable-library-js.5.17.2/DateOffset.js +252 -0
  86. package/dist/fable_modules/fable-library-js.5.17.2/DateOnly.js +124 -0
  87. package/dist/fable_modules/fable-library-js.5.17.2/DateOnlyTemporal.js +146 -0
  88. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeFormat.js +523 -0
  89. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeOffsetTemporal.js +283 -0
  90. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeTemporal.js +243 -0
  91. package/dist/fable_modules/fable-library-js.5.17.2/Decimal.js +238 -0
  92. package/dist/fable_modules/fable-library-js.5.17.2/Directory.js +11 -0
  93. package/dist/fable_modules/fable-library-js.5.17.2/Double.js +53 -0
  94. package/dist/fable_modules/fable-library-js.5.17.2/Encoding.js +185 -0
  95. package/dist/fable_modules/fable-library-js.5.17.2/Environment.js +3 -0
  96. package/dist/fable_modules/fable-library-js.5.17.2/Event.js +102 -0
  97. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Collections.js +45 -0
  98. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.CompilerServices.js +27 -0
  99. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.js +156 -0
  100. package/dist/fable_modules/fable-library-js.5.17.2/File.js +27 -0
  101. package/dist/fable_modules/fable-library-js.5.17.2/Global.js +29 -0
  102. package/dist/fable_modules/fable-library-js.5.17.2/Guid.js +163 -0
  103. package/dist/fable_modules/fable-library-js.5.17.2/Int32.js +135 -0
  104. package/dist/fable_modules/fable-library-js.5.17.2/List.js +1337 -0
  105. package/dist/fable_modules/fable-library-js.5.17.2/Long.js +38 -0
  106. package/dist/fable_modules/fable-library-js.5.17.2/MailboxProcessor.js +100 -0
  107. package/dist/fable_modules/fable-library-js.5.17.2/Map.js +1400 -0
  108. package/dist/fable_modules/fable-library-js.5.17.2/MapUtil.js +130 -0
  109. package/dist/fable_modules/fable-library-js.5.17.2/MutableMap.js +339 -0
  110. package/dist/fable_modules/fable-library-js.5.17.2/MutableSet.js +233 -0
  111. package/dist/fable_modules/fable-library-js.5.17.2/Native.js +14 -0
  112. package/dist/fable_modules/fable-library-js.5.17.2/Numeric.js +112 -0
  113. package/dist/fable_modules/fable-library-js.5.17.2/Observable.js +115 -0
  114. package/dist/fable_modules/fable-library-js.5.17.2/Option.js +87 -0
  115. package/dist/fable_modules/fable-library-js.5.17.2/Path.js +31 -0
  116. package/dist/fable_modules/fable-library-js.5.17.2/README.md +3 -0
  117. package/dist/fable_modules/fable-library-js.5.17.2/Random.js +172 -0
  118. package/dist/fable_modules/fable-library-js.5.17.2/Range.js +45 -0
  119. package/dist/fable_modules/fable-library-js.5.17.2/Reflection.js +489 -0
  120. package/dist/fable_modules/fable-library-js.5.17.2/RegExp.js +170 -0
  121. package/dist/fable_modules/fable-library-js.5.17.2/Result.js +165 -0
  122. package/dist/fable_modules/fable-library-js.5.17.2/Seq.js +1504 -0
  123. package/dist/fable_modules/fable-library-js.5.17.2/Seq2.js +111 -0
  124. package/dist/fable_modules/fable-library-js.5.17.2/Set.js +1829 -0
  125. package/dist/fable_modules/fable-library-js.5.17.2/String.js +731 -0
  126. package/dist/fable_modules/fable-library-js.5.17.2/System.Collections.Generic.js +333 -0
  127. package/dist/fable_modules/fable-library-js.5.17.2/System.Text.js +200 -0
  128. package/dist/fable_modules/fable-library-js.5.17.2/System.js +289 -0
  129. package/dist/fable_modules/fable-library-js.5.17.2/Task.js +27 -0
  130. package/dist/fable_modules/fable-library-js.5.17.2/TaskBuilder.js +72 -0
  131. package/dist/fable_modules/fable-library-js.5.17.2/TimeOnly.js +122 -0
  132. package/dist/fable_modules/fable-library-js.5.17.2/TimeOnlyTemporal.js +142 -0
  133. package/dist/fable_modules/fable-library-js.5.17.2/TimeSpan.js +180 -0
  134. package/dist/fable_modules/fable-library-js.5.17.2/TimeSpanTemporal.js +259 -0
  135. package/dist/fable_modules/fable-library-js.5.17.2/Timer.js +67 -0
  136. package/dist/fable_modules/fable-library-js.5.17.2/Types.js +198 -0
  137. package/dist/fable_modules/fable-library-js.5.17.2/Unicode.13.0.0.js +4 -0
  138. package/dist/fable_modules/fable-library-js.5.17.2/Uri.js +165 -0
  139. package/dist/fable_modules/fable-library-js.5.17.2/Util.js +807 -0
  140. package/dist/fable_modules/fable-library-js.5.17.2/big.d.ts +338 -0
  141. package/dist/fable_modules/fable-library-js.5.17.2/lib/big.js +829 -0
  142. package/dist/fable_modules/fable-library-js.5.17.2/package.json +24 -0
  143. package/dist/fable_modules/fable-library-js.5.17.2/quotation.js +682 -0
  144. package/package.json +1 -1
@@ -0,0 +1,483 @@
1
+ namespace FsToolkit.ErrorHandling
2
+
3
+ open System.Threading.Tasks
4
+ #if !FABLE_COMPILER
5
+ open System.Runtime.ExceptionServices
6
+ #endif
7
+
8
+ [<RequireQualifiedAccess>]
9
+ module AsyncResult =
10
+
11
+ let inline ok (value: 'ok) : Async<Result<'ok, 'error>> =
12
+ Ok value
13
+ |> Async.singleton
14
+
15
+ let inline error (error: 'error) : Async<Result<'ok, 'error>> =
16
+ Error error
17
+ |> Async.singleton
18
+
19
+ let inline map
20
+ ([<InlineIfLambda>] mapper: 'input -> 'output)
21
+ (input: Async<Result<'input, 'error>>)
22
+ : Async<Result<'output, 'error>> =
23
+ Async.map (Result.map mapper) input
24
+
25
+ let inline mapError
26
+ ([<InlineIfLambda>] mapper: 'inputError -> 'outputError)
27
+ (input: Async<Result<'ok, 'inputError>>)
28
+ : Async<Result<'ok, 'outputError>> =
29
+ Async.map (Result.mapError mapper) input
30
+
31
+ let inline bind
32
+ ([<InlineIfLambda>] binder: 'input -> Async<Result<'output, 'error>>)
33
+ (input: Async<Result<'input, 'error>>)
34
+ : Async<Result<'output, 'error>> =
35
+ Async.bind (Result.either binder error) input
36
+
37
+ let inline foldResult
38
+ ([<InlineIfLambda>] onSuccess: 'input -> 'output)
39
+ ([<InlineIfLambda>] onError: 'inputError -> 'output)
40
+ (input: Async<Result<'input, 'inputError>>)
41
+ : Async<'output> =
42
+ Async.map (Result.either onSuccess onError) input
43
+
44
+ let inline eitherMap ([<InlineIfLambda>] onSuccess) ([<InlineIfLambda>] onError) input =
45
+ Async.map (Result.eitherMap onSuccess onError) input
46
+
47
+ #if !FABLE_COMPILER
48
+
49
+ let inline ofTask (aTask: Task<'ok>) : Async<Result<'ok, exn>> =
50
+ async.Delay(fun () ->
51
+ aTask
52
+ |> Async.AwaitTask
53
+ |> Async.Catch
54
+ |> Async.map Result.ofChoice
55
+ )
56
+
57
+ let inline ofTaskAction (aTask: Task) : Async<Result<unit, exn>> =
58
+ async.Delay(fun () ->
59
+ aTask
60
+ |> Async.AwaitTask
61
+ |> Async.Catch
62
+ |> Async.map Result.ofChoice
63
+ )
64
+
65
+ #endif
66
+
67
+
68
+ let inline map2
69
+ ([<InlineIfLambda>] mapper: 'input1 -> 'input2 -> 'output)
70
+ (input1: Async<Result<'input1, 'error>>)
71
+ (input2: Async<Result<'input2, 'error>>)
72
+ : Async<Result<'output, 'error>> =
73
+ Async.map2 (Result.map2 mapper) input1 input2
74
+
75
+ let inline map3
76
+ ([<InlineIfLambda>] mapper: 'input1 -> 'input2 -> 'input3 -> 'output)
77
+ (input1: Async<Result<'input1, 'error>>)
78
+ (input2: Async<Result<'input2, 'error>>)
79
+ (input3: Async<Result<'input3, 'error>>)
80
+ : Async<Result<'output, 'error>> =
81
+ Async.map3 (Result.map3 mapper) input1 input2 input3
82
+
83
+ let inline apply
84
+ (applier: Async<Result<'input -> 'output, 'error>>)
85
+ (input: Async<Result<'input, 'error>>)
86
+ : Async<Result<'output, 'error>> =
87
+ map2 (fun f x -> f x) applier input
88
+
89
+
90
+ /// <summary>
91
+ /// Returns <paramref name="input"/> if it is <c>Ok</c>, otherwise returns <paramref name="ifError"/>
92
+ /// </summary>
93
+ /// <param name="ifError">The value to use if <paramref name="input"/> is <c>Error</c></param>
94
+ /// <param name="input">The input result.</param>
95
+ /// <remarks>
96
+ /// </remarks>
97
+ /// <example>
98
+ /// <code>
99
+ /// AsyncResult.error "First" |> AsyncResult.orElse (AsyncResult.error "Second") // evaluates to Error ("Second")
100
+ /// AsyncResult.error "First" |> AsyncResult.orElse (AsyncResult.ok "Second") // evaluates to Ok ("Second")
101
+ /// AsyncResult.ok "First" |> AsyncResult.orElse (AsyncResult.error "Second") // evaluates to Ok ("First")
102
+ /// AsyncResult.ok "First" |> AsyncResult.orElse (AsyncResult.ok "Second") // evaluates to Ok ("First")
103
+ /// </code>
104
+ /// </example>
105
+ /// <returns>
106
+ /// The result if the result is Ok, else returns <paramref name="ifError"/>.
107
+ /// </returns>
108
+ let inline orElse
109
+ (ifError: Async<Result<'ok, 'errorOutput>>)
110
+ (input: Async<Result<'ok, 'errorInput>>)
111
+ : Async<Result<'ok, 'errorOutput>> =
112
+ Async.bind (Result.either ok (fun _ -> ifError)) input
113
+
114
+ /// <summary>
115
+ /// Returns <paramref name="input"/> if it is <c>Ok</c>, otherwise executes <paramref name="ifErrorFunc"/> and returns the result.
116
+ /// </summary>
117
+ /// <param name="ifErrorFunc">A function that provides an alternate result when evaluated.</param>
118
+ /// <param name="input">The input result.</param>
119
+ /// <remarks>
120
+ /// <paramref name="ifErrorFunc"/> is not executed unless <paramref name="input"/> is an <c>Error</c>.
121
+ /// </remarks>
122
+ /// <example>
123
+ /// <code>
124
+ /// AsyncResult.error "First" |> AsyncResult.orElseWith (fun _ -> AsyncResult.error "Second") // evaluates to Error ("Second")
125
+ /// AsyncResult.error "First" |> AsyncResult.orElseWith (fun _ -> AsyncResult.ok "Second") // evaluates to Ok ("Second")
126
+ /// AsyncResult.ok "First" |> AsyncResult.orElseWith (fun _ -> AsyncResult.error "Second") // evaluates to Ok ("First")
127
+ /// AsyncResult.ok "First" |> AsyncResult.orElseWith (fun _ -> AsyncResult.ok "Second") // evaluates to Ok ("First")
128
+ /// </code>
129
+ /// </example>
130
+ /// <returns>
131
+ /// The result if the result is Ok, else the result of executing <paramref name="ifErrorFunc"/>.
132
+ /// </returns>
133
+ let inline orElseWith
134
+ ([<InlineIfLambda>] ifErrorFunc: 'errorInput -> Async<Result<'ok, 'errorOutput>>)
135
+ (input: Async<Result<'ok, 'errorInput>>)
136
+ : Async<Result<'ok, 'errorOutput>> =
137
+ Async.bind (Result.either ok ifErrorFunc) input
138
+
139
+ /// Replaces the wrapped value with unit
140
+ let inline ignore<'ok, 'error>
141
+ (value: Async<Result<'ok, 'error>>)
142
+ : Async<Result<unit, 'error>> =
143
+ value
144
+ |> map ignore<'ok>
145
+
146
+ /// Returns the specified error if the async-wrapped value is false.
147
+ let inline requireTrue (error: 'error) (value: Async<bool>) : Async<Result<unit, 'error>> =
148
+ value
149
+ |> Async.map (Result.requireTrue error)
150
+
151
+ /// Returns the specified error if the async-wrapped value is true.
152
+ let inline requireFalse (error: 'error) (value: Async<bool>) : Async<Result<unit, 'error>> =
153
+ value
154
+ |> Async.map (Result.requireFalse error)
155
+
156
+ // Converts an async-wrapped Option to a Result, using the given error if None.
157
+ let inline requireSome (error: 'error) (value: Async<'ok option>) : Async<Result<'ok, 'error>> =
158
+ value
159
+ |> Async.map (Result.requireSome error)
160
+
161
+ // Converts an async-wrapped Option to a Result, using the given error factory if None.
162
+ let inline requireSomeWith
163
+ ([<InlineIfLambda>] errorFactory: unit -> 'error)
164
+ (value: Async<'ok option>)
165
+ : Async<Result<'ok, 'error>> =
166
+ value
167
+ |> Async.map (Result.requireSomeWith errorFactory)
168
+
169
+ // Converts an async-wrapped Option to a Result, using the given error if Some.
170
+ let inline requireNone
171
+ (error: 'error)
172
+ (value: Async<'ok option>)
173
+ : Async<Result<unit, 'error>> =
174
+ value
175
+ |> Async.map (Result.requireNone error)
176
+
177
+ // Converts an async-wrapped Option to a Result, using the given error factory if Some.
178
+ let inline requireNoneWith
179
+ ([<InlineIfLambda>] errorFactory: unit -> 'error)
180
+ (value: Async<'ok option>)
181
+ : Async<Result<unit, 'error>> =
182
+ value
183
+ |> Async.map (Result.requireNoneWith errorFactory)
184
+
185
+ // Converts an async-wrapped ValueOption to a Result, using the given error if ValueNone.
186
+ let inline requireValueSome
187
+ (error: 'error)
188
+ (value: Async<'ok voption>)
189
+ : Async<Result<'ok, 'error>> =
190
+ value
191
+ |> Async.map (Result.requireValueSome error)
192
+
193
+ // Converts an async-wrapped ValueOption to a Result, using the given error if ValueSome.
194
+ let inline requireValueNone
195
+ (error: 'error)
196
+ (value: Async<'ok voption>)
197
+ : Async<Result<unit, 'error>> =
198
+ value
199
+ |> Async.map (Result.requireValueNone error)
200
+
201
+ /// Returns Ok if the async-wrapped value and the provided value are equal, or the specified error if not.
202
+ let inline requireEqual
203
+ (value1: 'value)
204
+ (value2: Async<'value>)
205
+ (error: 'error)
206
+ : Async<Result<unit, 'error>> =
207
+ value2
208
+ |> Async.map (fun x2' -> Result.requireEqual value1 x2' error)
209
+
210
+ /// Returns Ok if the two values are equal, or the specified error if not.
211
+ let inline requireEqualTo
212
+ (other: 'value)
213
+ (error: 'error)
214
+ (this: Async<'value>)
215
+ : Async<Result<unit, 'error>> =
216
+ this
217
+ |> Async.map (Result.requireEqualTo other error)
218
+
219
+ /// Returns Ok if the async-wrapped sequence is empty, or the specified error if not.
220
+ let inline requireEmpty
221
+ (error: 'error)
222
+ (values: Async<#seq<'ok>>)
223
+ : Async<Result<unit, 'error>> =
224
+ values
225
+ |> Async.map (Result.requireEmpty error)
226
+
227
+ /// Returns Ok if the async-wrapped sequence is not-empty, or the specified error if not.
228
+ let inline requireNotEmpty
229
+ (error: 'error)
230
+ (values: Async<#seq<'ok>>)
231
+ : Async<Result<unit, 'error>> =
232
+ values
233
+ |> Async.map (Result.requireNotEmpty error)
234
+
235
+ /// Returns the first item of the async-wrapped sequence if it exists, or the specified
236
+ /// error if the sequence is empty
237
+ let inline requireHead (error: 'error) (values: Async<#seq<'ok>>) : Async<Result<'ok, 'error>> =
238
+ values
239
+ |> Async.map (Result.requireHead error)
240
+
241
+
242
+ /// Returns the async-wrapped result if it is Ok and the predicate is true, or if the async wrapped result is Error.
243
+ /// If the predicate is false, returns a new async-wrapped Error result with the error value.
244
+ let inline require predicate error result =
245
+ result
246
+ |> Async.map (Result.require predicate error)
247
+
248
+ /// Replaces an error value of an async-wrapped result with a custom error
249
+ /// value.
250
+ let inline setError
251
+ (error: 'errorOutput)
252
+ (asyncResult: Async<Result<'ok, 'errorInput>>)
253
+ : Async<Result<'ok, 'errorOutput>> =
254
+ asyncResult
255
+ |> Async.map (Result.setError error)
256
+
257
+ /// Replaces a unit error value of an async-wrapped result with a custom
258
+ /// error value. Safer than setError since you're not losing any information.
259
+ let inline withError
260
+ (error: 'errorOutput)
261
+ (asyncResult: Async<Result<'ok, unit>>)
262
+ : Async<Result<'ok, 'errorOutput>> =
263
+ asyncResult
264
+ |> Async.map (Result.withError error)
265
+
266
+ /// Extracts the contained value of an async-wrapped result if Ok, otherwise
267
+ /// uses ifError.
268
+ let inline defaultValue (ifError: 'ok) (asyncResult: Async<Result<'ok, 'error>>) : Async<'ok> =
269
+ asyncResult
270
+ |> Async.map (Result.defaultValue ifError)
271
+
272
+ /// Extracts the contained value of an async-wrapped result if Error, otherwise
273
+ /// uses ifOk.
274
+ let inline defaultError
275
+ (ifOk: 'error)
276
+ (asyncResult: Async<Result<'ok, 'error>>)
277
+ : Async<'error> =
278
+ asyncResult
279
+ |> Async.map (Result.defaultError ifOk)
280
+
281
+ /// Extracts the contained value of an async-wrapped result if Ok, otherwise
282
+ /// evaluates ifErrorThunk and uses the result.
283
+ let inline defaultWith
284
+ ([<InlineIfLambda>] ifErrorThunk: 'error -> 'ok)
285
+ (asyncResult: Async<Result<'ok, 'error>>)
286
+ : Async<'ok> =
287
+ asyncResult
288
+ |> Async.map (Result.defaultWith ifErrorThunk)
289
+
290
+ /// Same as defaultValue for a result where the Ok value is unit. The name
291
+ /// describes better what is actually happening in this case.
292
+ let inline ignoreError<'error> (result: Async<Result<unit, 'error>>) : Async<unit> =
293
+ defaultValue () result
294
+
295
+ /// If the async-wrapped result is Ok, executes the function on the Ok value.
296
+ /// Passes through the input value.
297
+ let inline tee
298
+ ([<InlineIfLambda>] inspector: 'ok -> unit)
299
+ (asyncResult: Async<Result<'ok, 'error>>)
300
+ : Async<Result<'ok, 'error>> =
301
+ asyncResult
302
+ |> Async.map (Result.tee inspector)
303
+
304
+ /// If the async-wrapped result is Ok and the predicate returns true, executes
305
+ /// the function on the Ok value. Passes through the input value.
306
+ let inline teeIf
307
+ ([<InlineIfLambda>] predicate: 'ok -> bool)
308
+ ([<InlineIfLambda>] inspector: 'ok -> unit)
309
+ (asyncResult: Async<Result<'ok, 'error>>)
310
+ : Async<Result<'ok, 'error>> =
311
+ asyncResult
312
+ |> Async.map (Result.teeIf predicate inspector)
313
+
314
+ /// If the async-wrapped result is Error, executes the function on the Error
315
+ /// value. Passes through the input value.
316
+ let inline teeError
317
+ ([<InlineIfLambda>] teeFunction: 'error -> unit)
318
+ (asyncResult: Async<Result<'ok, 'error>>)
319
+ : Async<Result<'ok, 'error>> =
320
+ asyncResult
321
+ |> Async.map (Result.teeError teeFunction)
322
+
323
+ /// If the async-wrapped result is Error and the predicate returns true,
324
+ /// executes the function on the Error value. Passes through the input value.
325
+ let inline teeErrorIf
326
+ ([<InlineIfLambda>] predicate: 'error -> bool)
327
+ ([<InlineIfLambda>] teeFunction: 'error -> unit)
328
+ (asyncResult: Async<Result<'ok, 'error>>)
329
+ : Async<Result<'ok, 'error>> =
330
+ asyncResult
331
+ |> Async.map (Result.teeErrorIf predicate teeFunction)
332
+
333
+
334
+ /// Takes two results and returns a tuple of the pair
335
+ let inline zip
336
+ (left: Async<Result<'leftOk, 'error>>)
337
+ (right: Async<Result<'rightOk, 'error>>)
338
+ : Async<Result<'leftOk * 'rightOk, 'error>> =
339
+ Async.zip left right
340
+ |> Async.map (fun (r1, r2) -> Result.zip r1 r2)
341
+
342
+ /// Takes two results and returns a tuple of the error pair
343
+ let inline zipError
344
+ (left: Async<Result<'ok, 'leftError>>)
345
+ (right: Async<Result<'ok, 'rightError>>)
346
+ : Async<Result<'ok, 'leftError * 'rightError>> =
347
+ Async.zip left right
348
+ |> Async.map (fun (r1, r2) -> Result.zipError r1 r2)
349
+
350
+ /// Catches exceptions and maps them to the Error case using the provided function.
351
+ let inline catch
352
+ ([<InlineIfLambda>] exnMapper: exn -> 'error)
353
+ (input: Async<Result<'ok, 'error>>)
354
+ : Async<Result<'ok, 'error>> =
355
+ input
356
+ |> Async.Catch
357
+ |> Async.map (
358
+ function
359
+ | Choice1Of2(Ok v) -> Ok v
360
+ | Choice1Of2(Error err) -> Error err
361
+ | Choice2Of2 ex -> Error(exnMapper ex)
362
+ )
363
+
364
+ /// Gets the value in the Ok case or re-raises the exception in the Error case
365
+ let inline getOrReraise (input: Async<Result<'ok, exn>>) : Async<'ok> =
366
+ async {
367
+ match! input with
368
+ | Ok a -> return a
369
+ | Error exn ->
370
+ #if FABLE_COMPILER
371
+ return raise exn
372
+ #else
373
+ ExceptionDispatchInfo.Capture(exn).Throw()
374
+ return Unchecked.defaultof<_>
375
+ #endif
376
+ }
377
+
378
+ /// Lift Async to AsyncResult
379
+ let inline ofAsync (value: Async<'ok>) : Async<Result<'ok, 'error>> =
380
+ value
381
+ |> Async.map Ok
382
+
383
+ /// Lift Result to AsyncResult
384
+ let inline ofResult (x: Result<'ok, 'error>) : Async<Result<'ok, 'error>> =
385
+ x
386
+ |> Async.singleton
387
+
388
+ /// Bind the AsyncResult and requireSome on the inner option value.
389
+ let inline bindRequireSome error x =
390
+ x
391
+ |> bind (
392
+ Result.requireSome error
393
+ >> Async.singleton
394
+ )
395
+
396
+ /// Bind the AsyncResult and requireNone on the inner option value.
397
+ let inline bindRequireNone error x =
398
+ x
399
+ |> bind (
400
+ Result.requireNone error
401
+ >> Async.singleton
402
+ )
403
+
404
+ /// Bind the AsyncResult and requireValueSome on the inner voption value.
405
+ let inline bindRequireValueSome error x =
406
+ x
407
+ |> bind (
408
+ Result.requireValueSome error
409
+ >> Async.singleton
410
+ )
411
+
412
+ /// Bind the AsyncResult and requireValueNone on the inner voption value.
413
+ let inline bindRequireValueNone error x =
414
+ x
415
+ |> bind (
416
+ Result.requireValueNone error
417
+ >> Async.singleton
418
+ )
419
+
420
+ /// Bind the AsyncResult and requireTrue on the inner value.
421
+ let inline bindRequireTrue error x =
422
+ x
423
+ |> bind (
424
+ Result.requireTrue error
425
+ >> Async.singleton
426
+ )
427
+
428
+ /// Bind the AsyncResult and requireFalse on the inner value.
429
+ let inline bindRequireFalse error x =
430
+ x
431
+ |> bind (
432
+ Result.requireFalse error
433
+ >> Async.singleton
434
+ )
435
+
436
+ /// Bind the AsyncResult and requireNotNull on the inner value.
437
+ let inline bindRequireNotNull error x =
438
+ x
439
+ |> bind (
440
+ Result.requireNotNull error
441
+ >> Async.singleton
442
+ )
443
+
444
+ /// Bind the AsyncResult and requireEequal on the inner value.
445
+ let inline bindRequireEqual y error x =
446
+ x
447
+ |> bind (fun x ->
448
+ Result.requireEqual x y error
449
+ |> Async.singleton
450
+ )
451
+
452
+ /// Bind the AsyncResult and requireEmpty on the inner value.
453
+ let inline bindRequireEmpty error x =
454
+ x
455
+ |> bind (
456
+ Result.requireEmpty error
457
+ >> Async.singleton
458
+ )
459
+
460
+ /// Bind the AsyncResult and requireNotEmpty on the inner value.
461
+ let inline bindRequireNotEmpty error x =
462
+ x
463
+ |> bind (
464
+ Result.requireNotEmpty error
465
+ >> Async.singleton
466
+ )
467
+
468
+ /// Bind the AsyncResult and requireHead on the inner value
469
+ let inline bindRequireHead error x =
470
+ x
471
+ |> bind (
472
+ Result.requireHead error
473
+ >> Async.singleton
474
+ )
475
+
476
+ /// Returns the async-wrapped result if it is Ok and the checkFunc returns an async-wrapped Ok result or if the async-wrapped result is Error.
477
+ /// If the checkFunc returns an async-wrapped Error result, returns the async-wrapped Error result.
478
+ let inline check ([<InlineIfLambda>] checkFunc) (result) =
479
+ result
480
+ |> bind (fun o ->
481
+ checkFunc o
482
+ |> map (fun _ -> o)
483
+ )
@@ -0,0 +1,201 @@
1
+ namespace FsToolkit.ErrorHandling
2
+
3
+ open System.Threading.Tasks
4
+ open System
5
+
6
+ [<AutoOpen>]
7
+ module AsyncResultCE =
8
+
9
+ type AsyncResultBuilder() =
10
+
11
+ member inline _.Return(value: 'ok) : Async<Result<'ok, 'error>> =
12
+ result.Return value
13
+ |> async.Return
14
+
15
+ member inline _.ReturnFrom
16
+ (asyncResult: Async<Result<'ok, 'error>>)
17
+ : Async<Result<'ok, 'error>> =
18
+ asyncResult
19
+
20
+ member inline _.Zero() : Async<Result<unit, 'error>> =
21
+ result.Zero()
22
+ |> async.Return
23
+
24
+ member inline _.Bind
25
+ (
26
+ asyncResult: Async<Result<'okInput, 'error>>,
27
+ [<InlineIfLambda>] binder: 'okInput -> Async<Result<'okOutput, 'error>>
28
+ ) : Async<Result<'okOutput, 'error>> =
29
+ AsyncResult.bind binder asyncResult
30
+
31
+ member inline _.Delay
32
+ ([<InlineIfLambda>] generator: unit -> Async<Result<'ok, 'error>>)
33
+ : Async<Result<'ok, 'error>> =
34
+ async.Delay generator
35
+
36
+ member inline this.Combine
37
+ (computation1: Async<Result<unit, 'error>>, computation2: Async<Result<'ok, 'error>>)
38
+ : Async<Result<'ok, 'error>> =
39
+ this.Bind(computation1, (fun () -> computation2))
40
+
41
+ member inline _.TryWith
42
+ (
43
+ computation: Async<Result<'ok, 'error>>,
44
+ [<InlineIfLambda>] handler: System.Exception -> Async<Result<'ok, 'error>>
45
+ ) : Async<Result<'ok, 'error>> =
46
+ async.TryWith(computation, handler)
47
+
48
+ member inline _.TryFinally
49
+ (computation: Async<Result<'ok, 'error>>, [<InlineIfLambda>] compensation: unit -> unit)
50
+ : Async<Result<'ok, 'error>> =
51
+ async.TryFinally(computation, compensation)
52
+ #if !FABLE_COMPILER
53
+ member inline _.TryFinallyAsync
54
+ (
55
+ computation: Async<Result<'ok, 'error>>,
56
+ [<InlineIfLambda>] compensation: unit -> ValueTask
57
+ ) : Async<Result<'ok, 'error>> =
58
+ let compensation =
59
+ async {
60
+ let vTask = compensation ()
61
+
62
+ if vTask.IsCompletedSuccessfully then
63
+ return ()
64
+ else
65
+ return!
66
+ vTask.AsTask()
67
+ |> Async.AwaitTask
68
+ }
69
+
70
+ Async.TryFinallyAsync(computation, compensation)
71
+
72
+
73
+ member inline this.Using
74
+ (
75
+ resource: 'ok :> IAsyncDisposable,
76
+ [<InlineIfLambda>] binder: 'ok -> Async<Result<'U, 'error>>
77
+ ) : Async<Result<'U, 'error>> =
78
+ this.TryFinallyAsync(
79
+ binder resource,
80
+ (fun () ->
81
+ if not (isNull (box resource)) then
82
+ resource.DisposeAsync()
83
+ else
84
+ ValueTask()
85
+ )
86
+ )
87
+ #endif
88
+ member inline this.While
89
+ ([<InlineIfLambda>] guard: unit -> bool, computation: Async<Result<unit, 'error>>)
90
+ : Async<Result<unit, 'error>> =
91
+ if guard () then
92
+ let mutable whileAsync = Unchecked.defaultof<_>
93
+
94
+ whileAsync <-
95
+ this.Bind(computation, (fun () -> if guard () then whileAsync else this.Zero()))
96
+
97
+ whileAsync
98
+ else
99
+ this.Zero()
100
+
101
+
102
+ member inline _.BindReturn
103
+ (x: Async<Result<'okInput, 'error>>, [<InlineIfLambda>] f: 'okInput -> 'okOutput)
104
+ : Async<Result<'okOutput, 'error>> =
105
+ AsyncResult.map f x
106
+
107
+ /// <summary>
108
+ /// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
109
+ ///
110
+ /// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder
111
+ /// </summary>
112
+ member inline _.Source(result: Async<Result<'ok, 'error>>) : Async<Result<'ok, 'error>> =
113
+ result
114
+
115
+
116
+ let asyncResult = AsyncResultBuilder()
117
+
118
+ [<AutoOpen>]
119
+ module AsyncResultCEExtensions =
120
+
121
+ type AsyncResultBuilder with
122
+
123
+ /// <summary>
124
+ /// Needed to allow `for..in` and `for..do` functionality
125
+ /// </summary>
126
+ member inline _.Source(s: #seq<'value>) : #seq<'value> = s
127
+
128
+ /// <summary>
129
+ /// Method lets us transform data types into our internal representation.
130
+ /// </summary>
131
+ member inline _.Source(result: Result<'ok, 'error>) : Async<Result<'ok, 'error>> =
132
+ Async.singleton result
133
+
134
+ /// <summary>
135
+ /// Method lets us transform data types into our internal representation.
136
+ /// </summary>
137
+ member inline _.Source(choice: Choice<'ok, 'error>) : Async<Result<'ok, 'error>> =
138
+ choice
139
+ |> Result.ofChoice
140
+ |> Async.singleton
141
+
142
+ /// <summary>
143
+ /// Method lets us transform data types into our internal representation.
144
+ /// </summary>
145
+ member inline _.Source(asyncComputation: Async<'ok>) : Async<Result<'ok, 'error>> =
146
+ asyncComputation
147
+ |> Async.map Ok
148
+
149
+
150
+ member inline _.Using
151
+ (
152
+ resource: 'ok :> IDisposableNull,
153
+ [<InlineIfLambda>] binder: 'ok -> Async<Result<'U, 'error>>
154
+ ) : Async<Result<'U, 'error>> =
155
+ async.Using(resource, binder)
156
+
157
+
158
+ member inline this.For
159
+ (sequence: #seq<'ok>, [<InlineIfLambda>] binder: 'ok -> Async<Result<unit, 'error>>)
160
+ : Async<Result<unit, 'error>> =
161
+ this.Using(
162
+ sequence.GetEnumerator(),
163
+ fun enum ->
164
+ this.While(
165
+ (fun () -> enum.MoveNext()),
166
+ this.Delay(fun () -> binder enum.Current)
167
+ )
168
+ )
169
+
170
+
171
+ #if !FABLE_COMPILER
172
+ /// <summary>
173
+ /// Method lets us transform data types into our internal representation.
174
+ /// </summary>
175
+ member inline _.Source(task: Task<'ok>) : Async<Result<'ok, 'error>> =
176
+ task
177
+ |> Async.AwaitTask
178
+ |> Async.map Ok
179
+
180
+ /// <summary>
181
+ /// Method lets us transform data types into our internal representation.
182
+ /// </summary>
183
+ member inline _.Source(task: Task) : Async<Result<unit, 'error>> =
184
+ task
185
+ |> Async.AwaitTask
186
+ |> Async.map Ok
187
+ #endif
188
+
189
+ #if !FABLE_COMPILER
190
+ [<AutoOpen>]
191
+ module AsyncResultCEExtensions2 =
192
+
193
+ type AsyncResultBuilder with
194
+
195
+ /// <summary>
196
+ /// Method lets us transform data types into our internal representation.
197
+ /// </summary>
198
+ member inline _.Source(task: Task<Result<'ok, 'error>>) : Async<Result<'ok, 'error>> =
199
+ task
200
+ |> Async.AwaitTask
201
+ #endif