@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,731 @@
1
+ namespace FsToolkit.ErrorHandling
2
+
3
+
4
+ /// <summary>
5
+ /// Helper functions for working with <c>Result</c> values.
6
+ /// </summary>
7
+ [<RequireQualifiedAccess>]
8
+ module Result =
9
+
10
+ /// <summary>
11
+ /// Applies a transformation to the value of a <c>Result</c> to a new value using the specified mapper function.
12
+ ///
13
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/map</href>
14
+ /// </summary>
15
+ /// <param name="mapper">The function to apply to the value of the <c>Result</c> if it is <c>Ok</c>.</param>
16
+ /// <param name="input">The <c>Result</c> to map.</param>
17
+ /// <returns>A new <c>Result</c>with the mapped value if the input <c>Result</c> is <c>Ok</c>, otherwise the original <c>Error</c>.</returns>
18
+ let inline map
19
+ ([<InlineIfLambda>] mapper: 'okInput -> 'okOutput)
20
+ (input: Result<'okInput, 'error>)
21
+ : Result<'okOutput, 'error> =
22
+ match input with
23
+ | Ok x -> Ok(mapper x)
24
+ | Error e -> Error e
25
+
26
+ /// <summary>
27
+ /// Maps the error value of a <c>Result</c>to a new error value using the specified error mapper function.
28
+ ///
29
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/maperror</href>
30
+ /// </summary>
31
+ /// <param name="errorMapper">The function that maps the input error value to the output error value.</param>
32
+ /// <param name="input">The <c>Result</c>value to map the error value of.</param>
33
+ /// <returns>A new <c>Result</c>with the same Ok value and the mapped error value.</returns>
34
+ let inline mapError
35
+ ([<InlineIfLambda>] errorMapper: 'errorInput -> 'errorOutput)
36
+ (input: Result<'ok, 'errorInput>)
37
+ : Result<'ok, 'errorOutput> =
38
+ match input with
39
+ | Ok x -> Ok x
40
+ | Error e -> Error(errorMapper e)
41
+
42
+ /// <summary>
43
+ /// Takes a transformation function and applies it to the <c>Result</c> if it is <c>Ok</c>.
44
+ ///
45
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/bind</href>
46
+ /// </summary>
47
+ /// <param name="binder">The transformation function</param>
48
+ /// <param name="input">The input result</param>
49
+ /// <typeparam name="'okInput">The type of the successful result.</typeparam>
50
+ /// <typeparam name="'okOutput">The type of the result after binding.</typeparam>
51
+ /// <typeparam name="'error">The type of the error.</typeparam>
52
+ /// <returns>Returns a new <c>Result</c> if the input is <c>Ok</c>, otherwise returns the original <c>Result</c></returns>
53
+ let inline bind
54
+ ([<InlineIfLambda>] binder: 'okInput -> Result<'okOutput, 'error>)
55
+ (input: Result<'okInput, 'error>)
56
+ : Result<'okOutput, 'error> =
57
+ match input with
58
+ | Ok x -> binder x
59
+ | Error e -> Error e
60
+
61
+ /// <summary>
62
+ /// Determines whether the specified <c>Result</c> is in a successful state.
63
+ ///
64
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#isok</href>
65
+ /// </summary>
66
+ /// <param name="value">The result to check.</param>
67
+ /// <returns>True if the result is in a successful state; otherwise, false.</returns>
68
+ let inline isOk (value: Result<'ok, 'error>) : bool =
69
+ match value with
70
+ | Ok _ -> true
71
+ | Error _ -> false
72
+
73
+ /// <summary>
74
+ /// Determines whether the specified <c>Result</c> is an error.
75
+ ///
76
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#iserror</href>
77
+ /// </summary>
78
+ /// <param name="value">The result to check.</param>
79
+ /// <returns>True if the result is an error; otherwise, false.</returns>
80
+ let inline isError (value: Result<'ok, 'error>) : bool =
81
+ match value with
82
+ | Ok _ -> false
83
+ | Error _ -> true
84
+
85
+ /// <summary>
86
+ /// Applies the appropriate function based on the result of the input.
87
+ ///
88
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/eitherfunctions#result.either</href>
89
+ /// </summary>
90
+ /// <param name="onOk">The function to apply if the input is <c>Ok</c></param>
91
+ /// <param name="onError">The function to apply if the input is <c>Error</c></param>
92
+ /// <param name="input">The input result</param>
93
+ /// <returns>The result of applying the appropriate function.</returns>
94
+ let inline either
95
+ ([<InlineIfLambda>] onOk: 'okInput -> 'output)
96
+ ([<InlineIfLambda>] onError: 'errorInput -> 'output)
97
+ (input: Result<'okInput, 'errorInput>)
98
+ : 'output =
99
+ match input with
100
+ | Ok x -> onOk x
101
+ | Error err -> onError err
102
+
103
+ /// <summary>
104
+ /// Maps the values of a Result to a new Result using the provided functions.
105
+ ///
106
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/eitherfunctions#result.eithermap</href>
107
+ /// </summary>
108
+ /// <param name="onOk">The function to apply to the 'ok' value of the input Result.</param>
109
+ /// <param name="onError">The function to apply to the 'error' value of the input Result.</param>
110
+ /// <param name="input">The input <c>Result</c>to map.</param>
111
+ /// <returns>A new Result with the mapped values.</returns>
112
+ let inline eitherMap
113
+ ([<InlineIfLambda>] onOk: 'okInput -> 'okOutput)
114
+ ([<InlineIfLambda>] onError: 'errorInput -> 'errorOutput)
115
+ (input: Result<'okInput, 'errorInput>)
116
+ : Result<'okOutput, 'errorOutput> =
117
+ match input with
118
+ | Ok x -> Ok(onOk x)
119
+ | Error err -> Error(onError err)
120
+
121
+ /// <summary>
122
+ /// Applies a function to the value within a <c>Result</c> and returns a new <c>Result</c> with the output of the function.
123
+ ///
124
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/apply</href>
125
+ /// </summary>
126
+ /// <param name="applier">The <c>Result</c>containing the function to apply.</param>
127
+ /// <param name="input">The <c>Result</c>containing the input to apply the function to.</param>
128
+ /// <returns>A <c>Result</c>containing the output of applying the function to the input, or an <c>Error</c> if either <c>Result</c>is an <c>Error</c></returns>
129
+ let inline apply
130
+ (applier: Result<'okInput -> 'okOutput, 'error>)
131
+ (input: Result<'okInput, 'error>)
132
+ : Result<'okOutput, 'error> =
133
+ match (applier, input) with
134
+ | Ok f, Ok x -> Ok(f x)
135
+ | Error e, _
136
+ | _, Error e -> Error e
137
+
138
+ /// <summary>
139
+ /// Applies a mapper function to two input Results, producing a new <c>Result</c>.
140
+ ///
141
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/map2</href>
142
+ /// </summary>
143
+ /// <param name="mapper">The function to apply to the inputs.</param>
144
+ /// <param name="input1">The first input Result.</param>
145
+ /// <param name="input2">The second input Result.</param>
146
+ /// <returns>A new <c>Result</c>containing the output of the mapper function if both input Results are Ok, otherwise an Error Result.</returns>
147
+ let inline map2
148
+ ([<InlineIfLambda>] mapper: 'okInput1 -> 'okInput2 -> 'okOutput)
149
+ (input1: Result<'okInput1, 'error>)
150
+ (input2: Result<'okInput2, 'error>)
151
+ : Result<'okOutput, 'error> =
152
+ match (input1, input2) with
153
+ | Ok x, Ok y -> Ok(mapper x y)
154
+ | Error e, _
155
+ | _, Error e -> Error e
156
+
157
+ /// <summary>
158
+ /// Applies a mapper function to three input Results, producing a new <c>Result</c>.
159
+ ///
160
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/map3</href>
161
+ /// </summary>
162
+ /// <param name="mapper">The function to apply to the input results.</param>
163
+ /// <param name="input1">The first input result.</param>
164
+ /// <param name="input2">The second input result.</param>
165
+ /// <param name="input3">The third input result.</param>
166
+ /// <returns>A new <c>Result</c> with the output of the mapper function applied to the input results, if all Results are <c>Ok</c>, otherwise returns the original <c>Error</c></returns>
167
+ let inline map3
168
+ ([<InlineIfLambda>] mapper: 'okInput1 -> 'okInput2 -> 'okInput3 -> 'okOutput)
169
+ (input1: Result<'okInput1, 'error>)
170
+ (input2: Result<'okInput2, 'error>)
171
+ (input3: Result<'okInput3, 'error>)
172
+ : Result<'okOutput, 'error> =
173
+ match (input1, input2, input3) with
174
+ | Ok x, Ok y, Ok z -> Ok(mapper x y z)
175
+ | Error e, _, _
176
+ | _, Error e, _
177
+ | _, _, Error e -> Error e
178
+
179
+ /// <summary>
180
+ /// Converts a <c>Choice</c> to a <c>Result</c>
181
+ ///
182
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/transforms/ofchoice</href>
183
+ /// </summary>
184
+ /// <param name="input">The <c>Choice</c> value to convert.</param>
185
+ /// <returns>A <c>Result</c> matching the types of the input <c>Choice</c></returns>
186
+ let inline ofChoice (input: Choice<'ok, 'error>) : Result<'ok, 'error> =
187
+ match input with
188
+ | Choice1Of2 x -> Ok x
189
+ | Choice2Of2 e -> Error e
190
+
191
+ /// <summary>
192
+ /// Calls a <c>TryCreate</c> member function on a value passed in, returning a <c>Result</c> containing the value or an error tuple
193
+ ///
194
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/trycreate</href>
195
+ /// </summary>
196
+ /// <param name="fieldName">The name of the field</param>
197
+ /// <param name="x">The value to create a result from.</param>
198
+ /// <returns>A <c>Result</c> containing the value or an error tuple of the field name and the original error type</returns>
199
+ let inline tryCreate (fieldName: string) (x: 'a) : Result< ^b, (string * 'c) > =
200
+ let tryCreate' x =
201
+ (^b: (static member TryCreate: 'a -> Result< ^b, 'c >) x)
202
+
203
+ tryCreate' x
204
+ |> mapError (fun z -> (fieldName, z))
205
+
206
+ /// <summary>
207
+ /// Returns <paramref name="result"/> if it is <c>Ok</c>, otherwise returns <paramref name="ifError"/>
208
+ ///
209
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/orelsefunctions#result.orelse</href>
210
+ /// </summary>
211
+ /// <param name="ifError">The value to use if <paramref name="result"/> is <c>Error</c></param>
212
+ /// <param name="result">The input result.</param>
213
+ /// <remarks>
214
+ /// </remarks>
215
+ /// <example>
216
+ /// <code>
217
+ /// Error ("First") |> Result.orElse (Error ("Second")) // evaluates to Error ("Second")
218
+ /// Error ("First") |> Result.orElseWith (Ok ("Second")) // evaluates to Ok ("Second")
219
+ /// Ok ("First") |> Result.orElseWith (Error ("Second")) // evaluates to Ok ("First")
220
+ /// Ok ("First") |> Result.orElseWith (Ok ("Second")) // evaluates to Ok ("First")
221
+ /// </code>
222
+ /// </example>
223
+ /// <returns>
224
+ /// The result if the result is Ok, else returns <paramref name="ifError"/>.
225
+ /// </returns>
226
+ let inline orElse
227
+ (ifError: Result<'ok, 'errorOutput>)
228
+ (result: Result<'ok, 'error>)
229
+ : Result<'ok, 'errorOutput> =
230
+ match result with
231
+ | Ok x -> Ok x
232
+ | Error _ -> ifError
233
+
234
+ /// <summary>
235
+ /// Returns <paramref name="result"/> if it is <c>Ok</c>, otherwise executes <paramref name="ifErrorFunc"/> and returns the result.
236
+ ///
237
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/orelsefunctions#result.orelsewith</href>
238
+ /// </summary>
239
+ /// <param name="ifErrorFunc">A function that provides an alternate result when evaluated.</param>
240
+ /// <param name="result">The input result.</param>
241
+ /// <remarks>
242
+ /// <paramref name="ifErrorFunc"/> is not executed unless <paramref name="result"/> is an <c>Error</c>.
243
+ /// </remarks>
244
+ /// <example>
245
+ /// <code>
246
+ /// Error ("First") |> Result.orElseWith (fun _ -> Error ("Second")) // evaluates to Error ("Second")
247
+ /// Error ("First") |> Result.orElseWith (fun _ -> Ok ("Second")) // evaluates to Ok ("Second")
248
+ /// Ok ("First") |> Result.orElseWith (fun _ -> Error ("Second")) // evaluates to Ok ("First")
249
+ /// Ok ("First") |> Result.orElseWith (fun _ -> Ok ("Second")) // evaluates to Ok ("First")
250
+ /// </code>
251
+ /// </example>
252
+ /// <returns>
253
+ /// The result if the result is Ok, else the result of executing <paramref name="ifErrorFunc"/>.
254
+ /// </returns>
255
+ let inline orElseWith
256
+ ([<InlineIfLambda>] ifErrorFunc: 'error -> Result<'ok, 'errorOutput>)
257
+ (result: Result<'ok, 'error>)
258
+ : Result<'ok, 'errorOutput> =
259
+ match result with
260
+ | Ok x -> Ok x
261
+ | Error e -> ifErrorFunc e
262
+
263
+ /// <summary>
264
+ /// Ignores the value of a <c>Result</c> and returns a new <c>Result</c> with unit as the success value.
265
+ ///
266
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#ignore</href>
267
+ /// </summary>
268
+ /// <param name="result">The <c>Result</c> to ignore.</param>
269
+ /// <returns>A new <c>Result</c> with unit as the success value.</returns>
270
+ let inline ignore<'ok, 'error> (result: Result<'ok, 'error>) : Result<unit, 'error> =
271
+ match result with
272
+ | Ok _ -> Ok()
273
+ | Error e -> Error e
274
+
275
+ /// <summary>
276
+ /// Requires a boolean value to be true, otherwise returns an error result.
277
+ ///
278
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requiretrue</href>
279
+ /// </summary>
280
+ /// <param name="error">The error value to return if the condition is false.</param>
281
+ /// <param name="value">The boolean value to check.</param>
282
+ /// <returns>An <c>Ok</c> result if the condition is true, otherwise an Error result with the specified error value.</returns>
283
+ let inline requireTrue (error: 'error) (value: bool) : Result<unit, 'error> =
284
+ if value then Ok() else Error error
285
+
286
+ /// <summary>
287
+ /// Requires a boolean value to be false, otherwise returns an error result.
288
+ ///
289
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requirefalse</href>
290
+ /// </summary>
291
+ /// <param name="error">The error value to return if the condition is true.</param>
292
+ /// <param name="value">The boolean value to check.</param>
293
+ /// <returns>An <c>Ok</c> result if the condition is false, otherwise an Error result with the specified error value.</returns>
294
+ let inline requireFalse (error: 'error) (value: bool) : Result<unit, 'error> =
295
+ if not value then Ok() else Error error
296
+
297
+ /// <summary>
298
+ /// Requires a value to be <c>Some</c>, otherwise returns an error result.
299
+ ///
300
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requiresome</href>
301
+ /// </summary>
302
+ /// <param name="error">The error value to return if the value is <c>None</c>.</param>
303
+ /// <param name="option">The <c>Option</c> value to check.</param>
304
+ /// <returns>An <c>Ok</c> result if the value is <c>Some</c>, otherwise an Error result with the specified error value.</returns>
305
+ let inline requireSome (error: 'error) (option: 'ok option) : Result<'ok, 'error> =
306
+ match option with
307
+ | Some x -> Ok x
308
+ | None -> Error error
309
+
310
+ /// <summary>
311
+ /// Requires a value to be <c>Some</c>, otherwise returns an error result using the given error factory.
312
+ /// </summary>
313
+ /// <param name="errorFactory">A function to produce the error value if the value is <c>None</c>.</param>
314
+ /// <param name="option">The <c>Option</c> value to check.</param>
315
+ /// <returns>An <c>Ok</c> result if the value is <c>Some</c>, otherwise an Error result with the value produced by <paramref name="errorFactory" />.</returns>
316
+ let inline requireSomeWith
317
+ ([<InlineIfLambda>] errorFactory: unit -> 'error)
318
+ (option: 'ok option)
319
+ : Result<'ok, 'error> =
320
+ match option with
321
+ | Some x -> Ok x
322
+ | None -> Error(errorFactory ())
323
+
324
+ /// <summary>
325
+ /// Requires a value to be <c>None</c>, otherwise returns an error result.
326
+ ///
327
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requirenone</href>
328
+ /// </summary>
329
+ /// <param name="error">The error value to return if the value is <c>Some</c>.</param>
330
+ /// <param name="option">The <c>Option</c> value to check.</param>
331
+ /// <returns>An <c>Ok</c> result if the value is <c>None</c>, otherwise an Error result with the specified error value.</returns>
332
+ let inline requireNone (error: 'error) (option: 'value option) : Result<unit, 'error> =
333
+ match option with
334
+ | Some _ -> Error error
335
+ | None -> Ok()
336
+
337
+ /// <summary>
338
+ /// Requires a value to be <c>None</c>, otherwise returns an error result using the given error factory.
339
+ /// </summary>
340
+ /// <param name="errorFactory">A function to produce the error value if the value is <c>Some</c>.</param>
341
+ /// <param name="option">The <c>Option</c> value to check.</param>
342
+ /// <returns>An <c>Ok</c> result if the value is <c>None</c>, otherwise an Error result with the value produced by <paramref name="errorFactory" />.</returns>
343
+ let inline requireNoneWith
344
+ ([<InlineIfLambda>] errorFactory: unit -> 'error)
345
+ (option: 'value option)
346
+ : Result<unit, 'error> =
347
+ match option with
348
+ | Some _ -> Error(errorFactory ())
349
+ | None -> Ok()
350
+
351
+ /// <summary>
352
+ /// Requires a value to be <c>ValueSome</c>, otherwise returns an error result.
353
+ ///
354
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requirevaluesome</href>
355
+ /// </summary>
356
+ /// <param name="error">The error value to return if the value is <c>ValueNone</c>.</param>
357
+ /// <param name="voption">The <c>ValueOption</c> value to check.</param>
358
+ /// <returns>An <c>Ok</c> result if the value is <c>ValueSome</c>, otherwise an <c>Error</c> result with the specified error value.</returns>
359
+ let inline requireValueSome (error: 'error) (voption: 'ok voption) : Result<'ok, 'error> =
360
+ match voption with
361
+ | ValueSome x -> Ok x
362
+ | ValueNone -> Error error
363
+
364
+ /// <summary>
365
+ /// Requires a value to be <c>ValueNone</c>, otherwise returns an error result.
366
+ ///
367
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requirevaluenone</href>
368
+ /// </summary>
369
+ /// <param name="error">The error value to return if the value is <c>ValueSome</c>.</param>
370
+ /// <param name="voption">The <c>ValueOption</c> value to check.</param>
371
+ /// <returns>An <c>Ok</c> result if the value is <c>ValueNone</c>, otherwise an <c>Error</c> result with the specified error value.</returns>
372
+ let inline requireValueNone (error: 'error) (voption: 'value voption) : Result<unit, 'error> =
373
+ match voption with
374
+ | ValueSome _ -> Error error
375
+ | ValueNone -> Ok()
376
+
377
+ /// <summary>
378
+ /// Converts a nullable value into a <c>Result</c>, using the given error if null
379
+ ///
380
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requirenotnull</href>
381
+ /// </summary>
382
+ /// <param name="error">The error value to return if the value is null.</param>
383
+ /// <param name="value">The nullable value to check.</param>
384
+ /// <returns>An <c>Ok</c> result if the value is not null, otherwise an <c>Error</c> result with the specified error value.</returns>
385
+ let inline requireNotNull (error: 'error) (value: 'ok) : Result<'ok, 'error> =
386
+ match value with
387
+ | null -> Error error
388
+ | nonnull -> Ok nonnull
389
+
390
+ /// <summary>
391
+ /// Returns <c>Ok</c> if the two values are equal, or the specified error if not.
392
+ /// Same as <c>requireEqual</c>, but with a signature that fits piping better than normal function application.
393
+ ///
394
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requireequalto</href>
395
+ /// </summary>
396
+ /// <param name="other">The value to compare to.</param>
397
+ /// <param name="error">The error value to return if the values are not equal.</param>
398
+ /// <param name="this">The value to compare.</param>
399
+ /// <returns>An <c>Ok</c> result if the values are equal, otherwise an <c>Error</c> result with the specified error value.</returns>
400
+ let inline requireEqualTo
401
+ (other: 'value)
402
+ (error: 'error)
403
+ (this: 'value)
404
+ : Result<unit, 'error> =
405
+ if this = other then Ok() else Error error
406
+
407
+ /// <summary>
408
+ /// Returns <c>Ok</c> if the two values are equal, or the specified error if not.
409
+ /// Same as <c>requireEqualTo</c>, but with a signature that fits normal function application better than piping.
410
+ ///
411
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requireequal</href>
412
+ /// </summary>
413
+ /// <param name="x1">The first value to compare.</param>
414
+ /// <param name="x2">The second value to compare.</param>
415
+ /// <param name="error">The error value to return if the values are not equal.</param>
416
+ /// <returns>An <c>Ok</c> result if the values are equal, otherwise an <c>Error</c> result with the specified error value.</returns>
417
+ let inline requireEqual (x1: 'value) (x2: 'value) (error: 'error) : Result<unit, 'error> =
418
+ if x1 = x2 then Ok() else Error error
419
+
420
+ /// <summary>
421
+ /// Returns <c>Ok</c> if the sequence is empty, or the specified error if not.
422
+ ///
423
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requireempty</href>
424
+ /// </summary>
425
+ /// <param name="error">The error value to return if the sequence is not empty.</param>
426
+ /// <param name="xs">The sequence to check.</param>
427
+ /// <returns>An <c>Ok</c> result if the sequence is empty, otherwise an <c>Error</c> result with the specified error value.</returns>
428
+ let inline requireEmpty (error: 'error) (xs: #seq<'value>) : Result<unit, 'error> =
429
+ if Seq.isEmpty xs then Ok() else Error error
430
+
431
+ /// <summary>
432
+ /// Returns <c>Ok</c> if the sequence is not empty, or the specified error if it is.
433
+ ///
434
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requirenotempty</href>
435
+ /// </summary>
436
+ /// <param name="error">The error value to return if the sequence is empty.</param>
437
+ /// <param name="xs">The sequence to check.</param>
438
+ /// <returns>An <c>Ok</c> result if the sequence is not empty, otherwise an <c>Error</c> result with the specified error value.</returns>
439
+ let inline requireNotEmpty (error: 'error) (xs: #seq<'value>) : Result<unit, 'error> =
440
+ if Seq.isEmpty xs then Error error else Ok()
441
+
442
+ /// <summary>
443
+ /// Returns the first item of the sequence if it exists, or the specified error if the sequence is empty.
444
+ ///
445
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#requirehead</href>
446
+ /// </summary>
447
+ /// <param name="error">The error value to return if the sequence is empty.</param>
448
+ /// <param name="xs">The sequence to check.</param>
449
+ /// <returns>An <c>Ok</c> result containing the first item of the sequence if it exists, otherwise an <c>Error</c> result with the specified error value.</returns>
450
+ let inline requireHead (error: 'error) (xs: #seq<'ok>) : Result<'ok, 'error> =
451
+ match Seq.tryHead xs with
452
+ | Some x -> Ok x
453
+ | None -> Error error
454
+
455
+ /// <summary>
456
+ /// If the input result is <c>Ok</c>, applies a predicate to the <c>Ok</c> value.
457
+ /// If the predicate returns true, then returns the original <c>Ok</c> Result.
458
+ /// Otherwise, returns a new <c>Error</c> result with the provided error.
459
+ ///
460
+ /// If the input result is <c>Error</c>, just returns the input result.
461
+ ///
462
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/requirefunctions#require</href>
463
+ /// </summary>
464
+ /// <param name="predicate">Predicate applied to the <c>Ok</c> value of the result. </param>
465
+ /// <param name="error">The error to return if the predicate returns false.</param>
466
+ /// <param name="result">The input result.</param>
467
+ /// <returns> The input <paramref name="result"/> if it is <c>Error</c> or if the provided <paramref name="predicate"/> returns true. Otherwise returns a new <c>Error</c> result with the value <paramref name="error"/>.</returns>
468
+ let inline require
469
+ ([<InlineIfLambda>] predicate: 'ok -> bool)
470
+ (error: 'error)
471
+ (result: Result<'ok, 'error>)
472
+ : Result<'ok, 'error> =
473
+ match result with
474
+ | Error err -> Error err
475
+ | Ok ok -> if predicate ok then Ok ok else Error(error)
476
+
477
+ /// <summary>
478
+ /// Replaces an error value with a custom error value.
479
+ ///
480
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#seterror</href>
481
+ /// </summary>
482
+ /// <param name="error">The error value to replace the original error value with.</param>
483
+ /// <param name="result">The input result.</param>
484
+ /// <returns>A new <c>Result</c> with the same Ok value and the new error value.</returns>
485
+ let inline setError (error: 'error) (result: Result<'ok, 'errorIgnored>) : Result<'ok, 'error> =
486
+ result
487
+ |> mapError (fun _ -> error)
488
+
489
+ /// <summary>
490
+ /// Replaces a unit error value with a custom error value. Safer than setError
491
+ /// since you're not losing any information.
492
+ ///
493
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#witherror</href>
494
+ /// </summary>
495
+ /// <param name="error">The error value to replace the original error value with.</param>
496
+ /// <param name="result">The input result.</param>
497
+ /// <returns>A new <c>Result</c> with the same Ok value and the new error value.</returns>
498
+ let inline withError (error: 'error) (result: Result<'ok, unit>) : Result<'ok, 'error> =
499
+ result
500
+ |> mapError (fun () -> error)
501
+
502
+ /// <summary>
503
+ /// Returns the contained value if <c>Ok</c>, otherwise returns the provided value
504
+ ///
505
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#defaultvalue</href>
506
+ /// </summary>
507
+ /// <param name="ifError">The value to use if the result is <c>Error</c>.</param>
508
+ /// <param name="result">The input result.</param>
509
+ /// <returns>The contained value if <c>Ok</c>, otherwise <paramref name="ifError"/>.</returns>
510
+ let inline defaultValue (ifError: 'ok) (result: Result<'ok, 'error>) : 'ok =
511
+ match result with
512
+ | Ok x -> x
513
+ | Error _ -> ifError
514
+
515
+ /// <summary>
516
+ /// Returns the contained value if <c>Error</c>, otherwise returns the provided value
517
+ ///
518
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#defaulterror</href>
519
+ /// </summary>
520
+ /// <param name="ifOk">The value to use if the result is <c>Ok</c>.</param>
521
+ /// <param name="result">The input result.</param>
522
+ /// <returns>The contained value if <c>Error</c>, otherwise <paramref name="ifOk"/>.</returns>
523
+ let inline defaultError (ifOk: 'error) (result: Result<'ok, 'error>) : 'error =
524
+ match result with
525
+ | Error error -> error
526
+ | Ok _ -> ifOk
527
+
528
+ /// <summary>
529
+ /// Returns the contained value if <c>Ok</c>, otherwise evaluates <param name="ifErrorThunk"/> and returns the value.
530
+ ///
531
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#defaultwith</href>
532
+ /// </summary>
533
+ /// <param name="ifErrorThunk">The function to evaluate if the result is <c>Error</c>.</param>
534
+ /// <param name="result">The input result.</param>
535
+ /// <returns>The contained value if <c>Ok</c>, otherwise the result of evaluating <paramref name="ifErrorThunk"/>.</returns>
536
+ let inline defaultWith
537
+ ([<InlineIfLambda>] ifErrorThunk: 'error -> 'ok)
538
+ (result: Result<'ok, 'error>)
539
+ : 'ok =
540
+ match result with
541
+ | Ok x -> x
542
+ | Error e -> ifErrorThunk e
543
+
544
+ /// <summary>
545
+ /// Same as <c>defaultValue</c> for a result where the Ok value is unit. The name
546
+ /// describes better what is actually happening in this case.
547
+ ///
548
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#ignoreerror</href>
549
+ /// </summary>
550
+ /// <param name="result">The input result.</param>
551
+ /// <returns>Unit if <c>Ok</c>, otherwise the provided value.</returns>
552
+ let inline ignoreError<'error> (result: Result<unit, 'error>) : unit = defaultValue () result
553
+
554
+ /// <summary>
555
+ /// If the result is <c>Ok</c> and the predicate returns true, executes the function on the <c>Ok</c> value. Passes through the input value.
556
+ ///
557
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/teefunctions#teeif</href>
558
+ /// </summary>
559
+ /// <param name="predicate">The predicate to evaluate on the <c>Ok</c> value.</param>
560
+ /// <param name="sideEffect">The function to execute on the <c>Ok</c> value if the predicate returns true.</param>
561
+ /// <param name="result">The input result.</param>
562
+ /// <returns>The input result.</returns>
563
+ let inline teeIf
564
+ ([<InlineIfLambda>] predicate: 'ok -> bool)
565
+ ([<InlineIfLambda>] sideEffect: 'ok -> unit)
566
+ (result: Result<'ok, 'error>)
567
+ : Result<'ok, 'error> =
568
+ match result with
569
+ | Ok x ->
570
+ if predicate x then
571
+ sideEffect x
572
+ | Error _ -> ()
573
+
574
+ result
575
+
576
+ /// <summary>
577
+ /// If the result is <c>Error</c> and the predicate returns true, executes the
578
+ /// function on the <c>Error</c> value. Passes through the input value.
579
+ ///
580
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/teefunctions#teeerrorif</href>
581
+ /// </summary>
582
+ /// <param name="predicate">The predicate to evaluate on the <c>Error</c> value.</param>
583
+ /// <param name="sideEffect">The function to execute on the <c>Error</c> value if the predicate returns true.</param>
584
+ /// <param name="result">The input result.</param>
585
+ /// <returns>The input result.</returns>
586
+ let inline teeErrorIf
587
+ ([<InlineIfLambda>] predicate: 'error -> bool)
588
+ ([<InlineIfLambda>] sideEffect: 'error -> unit)
589
+ (result: Result<'ok, 'error>)
590
+ : Result<'ok, 'error> =
591
+ match result with
592
+ | Ok _ -> ()
593
+ | Error x ->
594
+ if predicate x then
595
+ sideEffect x
596
+
597
+ result
598
+
599
+ /// <summary>
600
+ /// If the result is <c>Ok</c>, executes the function on the <c>Ok</c> value. Passes through the input value.
601
+ ///
602
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/teefunctions#tee</href>
603
+ /// </summary>
604
+ /// <param name="sideEffect">The function to execute on the <c>Ok</c> value.</param>
605
+ /// <param name="result">The input result.</param>
606
+ /// <returns>The input result.</returns>
607
+ let inline tee
608
+ ([<InlineIfLambda>] sideEffect: 'ok -> unit)
609
+ (result: Result<'ok, 'error>)
610
+ : Result<'ok, 'error> =
611
+ teeIf (fun _ -> true) sideEffect result
612
+
613
+ /// <summary>
614
+ /// If the result is <c>Error</c>, executes the function on the <c>Error</c> value. Passes through the input value.
615
+ ///
616
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/teefunctions#teeerror</href>
617
+ /// </summary>
618
+ /// <param name="sideEffect">The function to execute on the <c>Error</c> value.</param>
619
+ /// <param name="result">The input result.</param>
620
+ /// <returns>The input result.</returns>
621
+ let inline teeError
622
+ ([<InlineIfLambda>] sideEffect: 'error -> unit)
623
+ (result: Result<'ok, 'error>)
624
+ : Result<'ok, 'error> =
625
+ teeErrorIf (fun _ -> true) sideEffect result
626
+
627
+ /// Converts a Result<Async<_>,_> to an Async<Result<_,_>>
628
+ let inline sequenceAsync (resAsync: Result<Async<'ok>, 'error>) : Async<Result<'ok, 'error>> =
629
+ async {
630
+ match resAsync with
631
+ | Ok asnc ->
632
+ let! x = asnc
633
+ return Ok x
634
+ | Error err -> return Error err
635
+ }
636
+
637
+ /// <summary>
638
+ /// Maps an Async function over a Result, returning an Async Result.
639
+ /// </summary>
640
+ /// <param name="f">The function to map over the Result.</param>
641
+ /// <param name="res">The Result to map over.</param>
642
+ /// <returns>An Async Result with the mapped value.</returns>
643
+ let inline traverseAsync
644
+ ([<InlineIfLambda>] f: 'okInput -> Async<'okOutput>)
645
+ (res: Result<'okInput, 'error>)
646
+ : Async<Result<'okOutput, 'error>> =
647
+ sequenceAsync ((map f) res)
648
+
649
+ #if !FABLE_COMPILER
650
+ open System.Threading.Tasks
651
+
652
+ /// Converts a Result<Async<_>,_> to an Async<Result<_,_>>
653
+ let sequenceTask (resTask: Result<Task<'a>, 'b>) : Task<Result<'a, 'b>> =
654
+ task {
655
+ match resTask with
656
+ | Ok task ->
657
+ let! x = task
658
+ return Ok x
659
+ | Error err -> return Error err
660
+ }
661
+ #endif
662
+
663
+ /// <summary>
664
+ /// Returns the <c>Ok</c> value or runs the specified function over the error value.
665
+ ///
666
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#valueor</href>
667
+ /// </summary>
668
+ /// <param name="f">The function to run over the error value.</param>
669
+ /// <param name="res">The input result.</param>
670
+ /// <returns>The <c>Ok</c> value if the result is <c>Ok</c>, otherwise the result of running the function over the error value.</returns>
671
+ let inline valueOr ([<InlineIfLambda>] f: 'error -> 'ok) (res: Result<'ok, 'error>) : 'ok =
672
+ match res with
673
+ | Ok x -> x
674
+ | Error x -> f x
675
+
676
+ /// <summary>
677
+ /// Takes two results and returns a tuple of the pair
678
+ ///
679
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/zip</href>
680
+ /// </summary>
681
+ /// <param name="left">The first input result.</param>
682
+ /// <param name="right">The second input result.</param>
683
+ /// <returns>A tuple of the pair of the input results.</returns>
684
+ let zip
685
+ (left: Result<'leftOk, 'error>)
686
+ (right: Result<'rightOk, 'error>)
687
+ : Result<'leftOk * 'rightOk, 'error> =
688
+ match left, right with
689
+ | Ok x1res, Ok x2res -> Ok(x1res, x2res)
690
+ | Error e, _ -> Error e
691
+ | _, Error e -> Error e
692
+
693
+ /// <summary>
694
+ /// Takes two results and returns a tuple of the error pair
695
+ ///
696
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/ziperror</href>
697
+ /// </summary>
698
+ /// <param name="left">The first input result.</param>
699
+ /// <param name="right">The second input result.</param>
700
+ /// <returns>A tuple of the error pair of the input results.</returns>
701
+ let zipError
702
+ (left: Result<'ok, 'leftError>)
703
+ (right: Result<'ok, 'rightError>)
704
+ : Result<'ok, 'leftError * 'rightError> =
705
+ match left, right with
706
+ | Error x1res, Error x2res -> Error(x1res, x2res)
707
+ | Ok e, _ -> Ok e
708
+ | _, Ok e -> Ok e
709
+
710
+
711
+ /// <summary>
712
+ /// When <paramref name="result"/> is <c>Ok</c>, applies <paramref name="checkFunc"/> to the <c>Ok</c> value.
713
+ /// If <paramref name="checkFunc"/> returns an <c>Ok</c> unit value, returns <paramref name="result"/>.
714
+ /// Otherwise, returns the <c>Error</c> value from the <paramref name="checkFunc"/> as a new result.
715
+ ///
716
+ /// When <paramref name="result"/> is <c>Error</c>, returns <paramref name="result"/>.
717
+ ///
718
+ /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/check</href>
719
+ /// </summary>
720
+ /// <param name="checkFunc">The function that performs a check against the <c>Ok</c> value of <paramref name="result"/>. Returns <c>Error</c> value from the function if error.</param>
721
+ /// <param name="result">The input result.</param>
722
+ /// <returns>The input <paramref name="result"/> if <c>Error</c> or <paramref name="checkFunc"/> returns a <c>Ok</c> result. Returns the <c>Error</c> value from <paramref name="checkFunc"/> if it returns an <c>Error</c> result.</returns>
723
+ let inline check
724
+ ([<InlineIfLambda>] checkFunc: 'ok -> Result<unit, 'error>)
725
+ (result: Result<'ok, 'error>)
726
+ : Result<'ok, 'error> =
727
+ match result with
728
+ | Error err -> Error err
729
+ | Ok ok ->
730
+ checkFunc ok
731
+ |> Result.map (fun _ -> ok)