@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.
- package/dist/Glutinum.Converter/FsharpAST.js +57 -17
- package/dist/Glutinum.Converter/FsharpAST.js.map +1 -1
- package/dist/Glutinum.Converter/Generate.js +5 -7
- package/dist/Glutinum.Converter/Generate.js.map +1 -1
- package/dist/Glutinum.Converter/GlueAST.js +71 -13
- package/dist/Glutinum.Converter/GlueAST.js.map +1 -1
- package/dist/Glutinum.Converter/Log.js +5 -5
- package/dist/Glutinum.Converter/Log.js.map +1 -1
- package/dist/Glutinum.Converter/Merge.js +7 -7
- package/dist/Glutinum.Converter/Printer.js +153 -73
- package/dist/Glutinum.Converter/Printer.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/Declaration.js +20 -19
- package/dist/Glutinum.Converter/Reader/Declaration.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/EnumDeclaration.js +4 -3
- package/dist/Glutinum.Converter/Reader/EnumDeclaration.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +2 -2
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +5 -6
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +42 -0
- package/dist/Glutinum.Converter/Reader/MappedTypeNode.js.map +1 -0
- package/dist/Glutinum.Converter/Reader/Node.js +8 -5
- package/dist/Glutinum.Converter/Reader/Node.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/Parameters.js +7 -4
- package/dist/Glutinum.Converter/Reader/Parameters.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/Report.js +35 -0
- package/dist/Glutinum.Converter/Reader/Report.js.map +1 -0
- package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -0
- package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/TypeNode.js +97 -27
- package/dist/Glutinum.Converter/Reader/TypeNode.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +31 -26
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +127 -0
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js.map +1 -0
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +7 -2
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +6 -9
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/Utils.js +1 -11
- package/dist/Glutinum.Converter/Reader/Utils.js.map +1 -1
- package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -2
- package/dist/Glutinum.Converter/Reader/VariableStatement.js.map +1 -1
- package/dist/Glutinum.Converter/Transform.js +327 -154
- package/dist/Glutinum.Converter/Transform.js.map +1 -1
- package/dist/Glutinum.Converter/TypeScript.Extensions.js +735 -0
- package/dist/Glutinum.Converter/TypeScript.Extensions.js.map +1 -0
- package/dist/Glutinum.Converter/Utils/Naming.js +6 -2
- package/dist/Glutinum.Converter/Utils/Naming.js.map +1 -1
- package/dist/Program.js +2 -2
- package/dist/Program.js.map +1 -1
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AssemblyInfo.fs +19 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Async.fs +207 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Async.fs.js +127 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Async.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOption.fs +81 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOptionCE.fs +183 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOptionCE.fs.js +37 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOptionCE.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncOptionOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResult.fs +439 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultCE.fs +217 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultCE.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOption.fs +75 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOption.fs.js +26 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOption.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOptionCE.fs +238 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOptionCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOptionCE.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncResultOptionOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidation.fs +190 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidationCE.fs +194 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidationCE.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/AsyncValidationOp.fs +35 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/FsToolkit.ErrorHandling.fableproj +51 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/List.fs +218 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/List.fs.js +358 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/List.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Option.fs +331 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/OptionCE.fs +186 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/OptionCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/OptionCE.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/OptionOp.fs +21 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Result.fs +644 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Result.fs.js +45 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Result.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultCE.fs +155 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultCE.fs.js +23 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultCE.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOp.fs +45 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOption.fs +201 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOption.fs.js +65 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOption.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOptionCE.fs +146 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOptionCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOptionCE.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ResultOptionOp.fs +57 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Seq.fs +19 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Seq.fs.js +31 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Seq.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Shims.fs +22 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Shims.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Shims.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/Validation.fs +172 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValidationCE.fs +148 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValidationCE.fs.js.map +1 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValidationOp.fs +35 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValueOption.fs +151 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/ValueOptionCE.fs +165 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Debug/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Debug/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Release/netstandard2.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Release/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.4.16.0/obj/Release/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/project_cracked.json +1 -1
- package/package.json +3 -2
- package/src/Glutinum.Converter/js/bootstrap.js +16 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
namespace FsToolkit.ErrorHandling
|
|
2
|
+
|
|
3
|
+
/// <summary>
|
|
4
|
+
/// Operators for working with the <c>Option</c> type.
|
|
5
|
+
/// </summary>
|
|
6
|
+
[<RequireQualifiedAccess>]
|
|
7
|
+
module Option =
|
|
8
|
+
|
|
9
|
+
/// <summary>
|
|
10
|
+
/// Binds a function to an option, applying the function to the value if the option is <c>Some</c>.
|
|
11
|
+
///
|
|
12
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/bind</href>
|
|
13
|
+
/// </summary>
|
|
14
|
+
/// <param name="mapper">The function to apply to the value.</param>
|
|
15
|
+
/// <param name="input">The input option.</param>
|
|
16
|
+
/// <typeparam name="'TInput">The input type of the option.</typeparam>
|
|
17
|
+
/// <typeparam name="'TOutput">The output type of the option.</typeparam>
|
|
18
|
+
/// <returns>The result of applying the function to the value, or <c>None</c> if the option is <c>None</c>.</returns>
|
|
19
|
+
let inline bind
|
|
20
|
+
([<InlineIfLambda>] mapper: 'TInput -> 'TOutput option)
|
|
21
|
+
(input: 'TInput option)
|
|
22
|
+
: 'TOutput option =
|
|
23
|
+
match input with
|
|
24
|
+
| Some v -> mapper v
|
|
25
|
+
| None -> None
|
|
26
|
+
|
|
27
|
+
/// <summary>
|
|
28
|
+
/// Applies a mapper function to the value inside an option, returning a new option with the mapped value.
|
|
29
|
+
///
|
|
30
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/map</href>
|
|
31
|
+
/// </summary>
|
|
32
|
+
/// <param name="mapper">The function to apply to the value inside the option.</param>
|
|
33
|
+
/// <param name="input">The input option.</param>
|
|
34
|
+
/// <returns>An option with the mapped value if the input option is <c>Some</c>, otherwise <c>None</c>.</returns>
|
|
35
|
+
let inline map
|
|
36
|
+
([<InlineIfLambda>] mapper: 'TInput -> 'TOutput)
|
|
37
|
+
(input: 'TInput option)
|
|
38
|
+
: 'TOutput option =
|
|
39
|
+
match input with
|
|
40
|
+
| Some v -> Some(mapper v)
|
|
41
|
+
| None -> None
|
|
42
|
+
|
|
43
|
+
/// <summary>
|
|
44
|
+
/// Applies a mapper function to the values inside two options, returning a new option with the mapped value.
|
|
45
|
+
///
|
|
46
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/map2</href>
|
|
47
|
+
/// </summary>
|
|
48
|
+
/// <param name="mapper">The function to apply to the values inside the options.</param>
|
|
49
|
+
/// <param name="input1">The first input option.</param>
|
|
50
|
+
/// <param name="input2">The second input option.</param>
|
|
51
|
+
/// <returns>An option with the mapped value if both input options are <c>Some</c>, otherwise <c>None</c>.</returns>
|
|
52
|
+
let inline map2
|
|
53
|
+
([<InlineIfLambda>] mapper: 'TInput1 -> 'TInput2 -> 'TOutput)
|
|
54
|
+
(input1: 'TInput1 option)
|
|
55
|
+
(input2: 'TInput2 option)
|
|
56
|
+
: 'TOutput option =
|
|
57
|
+
match (input1, input2) with
|
|
58
|
+
| Some x, Some y -> Some(mapper x y)
|
|
59
|
+
| _ -> None
|
|
60
|
+
|
|
61
|
+
/// <summary>
|
|
62
|
+
/// Applies a mapper function to the values inside three options, returning a new option with the mapped value.
|
|
63
|
+
///
|
|
64
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/map3</href>
|
|
65
|
+
/// </summary>
|
|
66
|
+
/// <param name="mapper">The function to apply to the values inside the options.</param>
|
|
67
|
+
/// <param name="input1">The first input option.</param>
|
|
68
|
+
/// <param name="input2">The second input option.</param>
|
|
69
|
+
/// <param name="input3">The third input option.</param>
|
|
70
|
+
/// <returns>An option with the mapped value if all input options are <c>Some</c>, otherwise <c>None</c>.</returns>
|
|
71
|
+
let inline map3
|
|
72
|
+
([<InlineIfLambda>] mapper: 'TInput1 -> 'TInput2 -> 'TInput3 -> 'TOutput)
|
|
73
|
+
(input1: 'TInput1 option)
|
|
74
|
+
(input2: 'TInput2 option)
|
|
75
|
+
(input3: 'TInput3 option)
|
|
76
|
+
: 'TOutput option =
|
|
77
|
+
match (input1, input2, input3) with
|
|
78
|
+
| Some x, Some y, Some z -> Some(mapper x y z)
|
|
79
|
+
| _ -> None
|
|
80
|
+
|
|
81
|
+
/// <summary>
|
|
82
|
+
/// Ignores the value of an option and returns a unit option.
|
|
83
|
+
/// </summary>
|
|
84
|
+
/// <param name="opt">The option to ignore.</param>
|
|
85
|
+
/// <returns>A unit option.</returns>
|
|
86
|
+
let inline ignore (opt: 'T option) : unit option =
|
|
87
|
+
match opt with
|
|
88
|
+
| Some _ -> Some()
|
|
89
|
+
| None -> None
|
|
90
|
+
|
|
91
|
+
/// <summary>
|
|
92
|
+
/// Converts a value option to a regular option.
|
|
93
|
+
///
|
|
94
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/transforms/ofvalueoption</href>
|
|
95
|
+
/// </summary>
|
|
96
|
+
/// <param name="vopt">The value option to convert.</param>
|
|
97
|
+
/// <returns>The converted regular option.</returns>
|
|
98
|
+
let inline ofValueOption (vopt: 'value voption) : 'value option =
|
|
99
|
+
match vopt with
|
|
100
|
+
| ValueSome v -> Some v
|
|
101
|
+
| ValueNone -> None
|
|
102
|
+
|
|
103
|
+
/// <summary>
|
|
104
|
+
/// Converts an option value to a value option.
|
|
105
|
+
///
|
|
106
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/transforms/tovalueoption</href>
|
|
107
|
+
/// </summary>
|
|
108
|
+
/// <param name="opt">The option value to convert.</param>
|
|
109
|
+
/// <returns>A value option.</returns>
|
|
110
|
+
let inline toValueOption (opt: 'value option) : 'value voption =
|
|
111
|
+
match opt with
|
|
112
|
+
| Some v -> ValueSome v
|
|
113
|
+
| None -> ValueNone
|
|
114
|
+
|
|
115
|
+
/// <summary>
|
|
116
|
+
/// Traverses an option value and applies a function to its inner value, returning a result.
|
|
117
|
+
/// </summary>
|
|
118
|
+
/// <param name="binder">The function to apply to the inner value of the option.</param>
|
|
119
|
+
/// <param name="input">The option value to traverse.</param>
|
|
120
|
+
/// <returns>A result containing either an option with the transformed value or an error.</returns>
|
|
121
|
+
let inline traverseResult
|
|
122
|
+
([<InlineIfLambda>] binder: 'input -> Result<'okOutput, 'error>)
|
|
123
|
+
(input: option<'input>)
|
|
124
|
+
: Result<'okOutput option, 'error> =
|
|
125
|
+
match input with
|
|
126
|
+
| None -> Ok None
|
|
127
|
+
| Some v ->
|
|
128
|
+
binder v
|
|
129
|
+
|> Result.map Some
|
|
130
|
+
|
|
131
|
+
let inline sequenceResult (opt: Result<'ok, 'error> option) : Result<'ok option, 'error> =
|
|
132
|
+
traverseResult id opt
|
|
133
|
+
|
|
134
|
+
#if !FABLE_COMPILER
|
|
135
|
+
/// <summary>
|
|
136
|
+
/// Tries to parse a string value into a specified type using the TryParse method of the type.
|
|
137
|
+
/// </summary>
|
|
138
|
+
/// <typeparam name="^value">The type to parse the string value into, if it has a <c>TryParse</c> function</typeparam>
|
|
139
|
+
/// <param name="valueToParse">The string value to parse.</param>
|
|
140
|
+
/// <returns>An option containing the parsed value if successful, or None if parsing fails.</returns>
|
|
141
|
+
let inline tryParse< ^value
|
|
142
|
+
when ^value: (static member TryParse: string * byref< ^value > -> bool)>
|
|
143
|
+
(valueToParse: string)
|
|
144
|
+
: ^value option =
|
|
145
|
+
let mutable output = Unchecked.defaultof< ^value>
|
|
146
|
+
|
|
147
|
+
let parsed =
|
|
148
|
+
(^value: (static member TryParse: string * byref< ^value > -> bool) (valueToParse,
|
|
149
|
+
&output))
|
|
150
|
+
|
|
151
|
+
match parsed with
|
|
152
|
+
| true -> Some output
|
|
153
|
+
| _ -> None
|
|
154
|
+
|
|
155
|
+
/// <summary>
|
|
156
|
+
/// Tries to get the value associated with the specified key from the dictionary.
|
|
157
|
+
/// </summary>
|
|
158
|
+
/// <param name="key">The key to look up in the dictionary.</param>
|
|
159
|
+
/// <param name="dictionary">The dictionary to search for the key.</param>
|
|
160
|
+
/// <typeparam name="^Dictionary">The type of the dictionary, assuming it has a <c>TryGetValue</c> member accessible</typeparam>
|
|
161
|
+
/// <returns>
|
|
162
|
+
/// An option containing the value associated with the key if it exists in the dictionary,
|
|
163
|
+
/// or None if the key does not exist.
|
|
164
|
+
/// </returns>
|
|
165
|
+
let inline tryGetValue (key: 'key) (dictionary: ^Dictionary) : ^value option =
|
|
166
|
+
let mutable output = Unchecked.defaultof< ^value>
|
|
167
|
+
|
|
168
|
+
let parsed =
|
|
169
|
+
(^Dictionary: (member TryGetValue: 'key * byref< ^value > -> bool) (dictionary,
|
|
170
|
+
key,
|
|
171
|
+
&output))
|
|
172
|
+
|
|
173
|
+
match parsed with
|
|
174
|
+
| true -> Some output
|
|
175
|
+
| false -> None
|
|
176
|
+
#endif
|
|
177
|
+
|
|
178
|
+
/// <summary>
|
|
179
|
+
/// Takes two options and returns a tuple of the pair or <c>None</c> if either are <c>None</c>
|
|
180
|
+
///
|
|
181
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/zip</href>
|
|
182
|
+
/// </summary>
|
|
183
|
+
/// <param name="left">The input option</param>
|
|
184
|
+
/// <param name="right">The input option</param>
|
|
185
|
+
/// <returns></returns>
|
|
186
|
+
let inline zip (left: 'left option) (right: 'right option) : ('left * 'right) option =
|
|
187
|
+
match left, right with
|
|
188
|
+
| Some v1, Some v2 -> Some(v1, v2)
|
|
189
|
+
| _ -> None
|
|
190
|
+
|
|
191
|
+
/// <summary>
|
|
192
|
+
/// Converts a <c>Result</c> to an <c>option</c>.
|
|
193
|
+
///
|
|
194
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/transforms/ofresult</href>
|
|
195
|
+
/// </summary>
|
|
196
|
+
/// <param name="r">The result to convert.</param>
|
|
197
|
+
/// <returns>An option containing the value if the result is <c>Ok</c>, or <c>None</c> if the result is <c>Error</c></returns>
|
|
198
|
+
let inline ofResult (r: Result<'ok, 'error>) : 'ok option =
|
|
199
|
+
match r with
|
|
200
|
+
| Ok v -> Some v
|
|
201
|
+
| Error _ -> None
|
|
202
|
+
|
|
203
|
+
/// <summary>
|
|
204
|
+
/// Convert a potentially null value to an option.
|
|
205
|
+
///
|
|
206
|
+
/// This is different from <see cref="FSharp.Core.Option.ofObj">Option.ofObj</see> where it doesn't require the value to be constrained to null.
|
|
207
|
+
/// This is beneficial where third party APIs may generate a record type using reflection and it can be null.
|
|
208
|
+
/// See <a href="https://latkin.org/blog/2015/05/18/null-checking-considerations-in-f-its-harder-than-you-think/">Null-checking considerations in F#</a> for more details.
|
|
209
|
+
///
|
|
210
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/transforms/ofnull</href>
|
|
211
|
+
/// </summary>
|
|
212
|
+
/// <param name="value">The potentially null value</param>
|
|
213
|
+
/// <returns>An option</returns>
|
|
214
|
+
/// <seealso cref="FSharp.Core.Option.ofObj"/>
|
|
215
|
+
let inline ofNull (value: 'nullableValue) : 'nullableValue option =
|
|
216
|
+
if System.Object.ReferenceEquals(value, null) then
|
|
217
|
+
None
|
|
218
|
+
else
|
|
219
|
+
Some value
|
|
220
|
+
|
|
221
|
+
/// <summary>
|
|
222
|
+
///
|
|
223
|
+
/// <c>bindNull binder option</c> evaluates to <c>match option with None -> None | Some x -> binder x |> Option.ofNull</c>
|
|
224
|
+
///
|
|
225
|
+
/// Automatically onverts the result of binder that is pontentially null into an option.
|
|
226
|
+
///
|
|
227
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/bindnull</href>
|
|
228
|
+
/// </summary>
|
|
229
|
+
/// <param name="binder">A function that takes the value of type 'value from an option and transforms it into
|
|
230
|
+
/// a value of type 'nullableValue.</param>
|
|
231
|
+
/// <param name="option">The input option</param>
|
|
232
|
+
/// <typeparam name="'value"></typeparam>
|
|
233
|
+
/// <typeparam name="'nullableValue"></typeparam>
|
|
234
|
+
/// <returns>An option of the output type of the binder.</returns>
|
|
235
|
+
/// <seealso cref="ofNull"/>
|
|
236
|
+
let inline bindNull
|
|
237
|
+
([<InlineIfLambda>] binder: 'value -> 'nullableValue)
|
|
238
|
+
(option: Option<'value>)
|
|
239
|
+
: 'nullableValue option =
|
|
240
|
+
match option with
|
|
241
|
+
| Some x ->
|
|
242
|
+
binder x
|
|
243
|
+
|> ofNull
|
|
244
|
+
| None -> None
|
|
245
|
+
|
|
246
|
+
/// <summary>
|
|
247
|
+
/// Returns result of running <paramref name="onSome"/> if it is <c>Some</c>, otherwise returns result of running <paramref name="onNone"/>
|
|
248
|
+
///
|
|
249
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/either</href>
|
|
250
|
+
/// </summary>
|
|
251
|
+
/// <param name="onSome">The function to run if <paramref name="input"/> is <c>Some</c></param>
|
|
252
|
+
/// <param name="onNone">The function to run if <paramref name="input"/> is <c>None</c></param>
|
|
253
|
+
/// <param name="input">The input option.</param>
|
|
254
|
+
/// <returns>
|
|
255
|
+
/// The result of running <paramref name="onSome"/> if the input is <c>Some</c>, else returns result of running <paramref name="onNone"/>.
|
|
256
|
+
/// </returns>
|
|
257
|
+
let inline either
|
|
258
|
+
([<InlineIfLambda>] onSome: 'a -> 'output)
|
|
259
|
+
([<InlineIfLambda>] onNone: unit -> 'output)
|
|
260
|
+
(input: 'a option)
|
|
261
|
+
: 'output =
|
|
262
|
+
match input with
|
|
263
|
+
| Some x -> onSome x
|
|
264
|
+
| None -> onNone ()
|
|
265
|
+
|
|
266
|
+
/// <summary>
|
|
267
|
+
/// If the option is <c>Some</c>, executes the function on the <c>Some</c> value and passes through the input value.
|
|
268
|
+
///
|
|
269
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/teefunctions#teesome</href>
|
|
270
|
+
/// </summary>
|
|
271
|
+
/// <param name="f">The function to execute on the <c>Some</c> value.</param>
|
|
272
|
+
/// <param name="opt">The input option.</param>
|
|
273
|
+
/// <returns>The input option</returns>
|
|
274
|
+
let inline teeSome ([<InlineIfLambda>] f: 'T -> unit) (opt: 'T option) : 'T option =
|
|
275
|
+
match opt with
|
|
276
|
+
| Some x -> f x
|
|
277
|
+
| None -> ()
|
|
278
|
+
|
|
279
|
+
opt
|
|
280
|
+
|
|
281
|
+
/// <summary>
|
|
282
|
+
/// If the option is <c>None</c>, executes the function and passes through the input value.
|
|
283
|
+
///
|
|
284
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/teefunctions#teenone</href>
|
|
285
|
+
/// </summary>
|
|
286
|
+
/// <param name="f">The function to execute if the input is <c>None</c>.</param>
|
|
287
|
+
/// <param name="opt">The input option.</param>
|
|
288
|
+
/// <returns>The input option</returns>
|
|
289
|
+
let inline teeNone (f: unit -> unit) (opt: 'T option) : 'T option =
|
|
290
|
+
match opt with
|
|
291
|
+
| Some _ -> ()
|
|
292
|
+
| None -> f ()
|
|
293
|
+
|
|
294
|
+
opt
|
|
295
|
+
|
|
296
|
+
/// <summary>
|
|
297
|
+
/// If the result is <c>Some</c> and the predicate returns true, executes the function
|
|
298
|
+
/// on the <c>Some</c> value and passes through the input value.
|
|
299
|
+
///
|
|
300
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/teefunctions#teeif</href>
|
|
301
|
+
/// </summary>
|
|
302
|
+
/// <param name="predicate">The predicate to execute on the <c>Some</c> value.</param>
|
|
303
|
+
/// <param name="f">The function to execute on the <c>Some</c> value if the predicate proves true</param>
|
|
304
|
+
/// <param name="opt">The input option.</param>
|
|
305
|
+
/// <returns>The input option</returns>
|
|
306
|
+
let inline teeIf
|
|
307
|
+
([<InlineIfLambda>] predicate: 'T -> bool)
|
|
308
|
+
([<InlineIfLambda>] f: 'T -> unit)
|
|
309
|
+
(opt: 'T option)
|
|
310
|
+
: 'T option =
|
|
311
|
+
match opt with
|
|
312
|
+
| Some x ->
|
|
313
|
+
if predicate x then
|
|
314
|
+
f x
|
|
315
|
+
| None -> ()
|
|
316
|
+
|
|
317
|
+
opt
|
|
318
|
+
|
|
319
|
+
/// <summary>
|
|
320
|
+
/// Creates an option from a boolean value and a value of type 'a.
|
|
321
|
+
/// If the boolean value is true, returns <c>Some</c> value.
|
|
322
|
+
/// If the boolean value is false, returns <c>None</c>.
|
|
323
|
+
///
|
|
324
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/transforms/ofpair</href>
|
|
325
|
+
/// </summary>
|
|
326
|
+
/// <param name="input">A tuple containing a boolean value and a value of type 'a.</param>
|
|
327
|
+
/// <returns>An option value.</returns>
|
|
328
|
+
let inline ofPair (input: bool * 'a) =
|
|
329
|
+
match input with
|
|
330
|
+
| true, x -> Some x
|
|
331
|
+
| false, _ -> None
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
namespace FsToolkit.ErrorHandling
|
|
2
|
+
|
|
3
|
+
[<AutoOpen>]
|
|
4
|
+
module OptionCE =
|
|
5
|
+
open System
|
|
6
|
+
|
|
7
|
+
type OptionBuilder() =
|
|
8
|
+
member inline _.Return(x: 'value) : 'value option = Some x
|
|
9
|
+
|
|
10
|
+
member inline _.ReturnFrom(m: 'value option) : 'value option = m
|
|
11
|
+
|
|
12
|
+
member inline _.Bind
|
|
13
|
+
(
|
|
14
|
+
input: 'input option,
|
|
15
|
+
[<InlineIfLambda>] binder: 'input -> 'output option
|
|
16
|
+
) : 'output option =
|
|
17
|
+
Option.bind binder input
|
|
18
|
+
|
|
19
|
+
// Could not get it to work solely with Source. In loop cases it would potentially match the #seq overload and ask for type annotation
|
|
20
|
+
member inline this.Bind
|
|
21
|
+
(
|
|
22
|
+
m: 'input when 'input: null,
|
|
23
|
+
[<InlineIfLambda>] binder: 'input -> 'output option
|
|
24
|
+
) : 'output option =
|
|
25
|
+
this.Bind(Option.ofObj m, binder)
|
|
26
|
+
|
|
27
|
+
member inline this.Zero() : unit option = this.Return()
|
|
28
|
+
|
|
29
|
+
member inline _.Combine
|
|
30
|
+
(
|
|
31
|
+
m: 'input option,
|
|
32
|
+
[<InlineIfLambda>] binder: 'input -> 'output option
|
|
33
|
+
) : 'output option =
|
|
34
|
+
Option.bind binder m
|
|
35
|
+
|
|
36
|
+
member inline this.Combine(m1: unit option, m2: 'output option) : 'output option =
|
|
37
|
+
this.Bind(m1, (fun () -> m2))
|
|
38
|
+
|
|
39
|
+
member inline _.Delay
|
|
40
|
+
([<InlineIfLambda>] delayer: unit -> 'value option)
|
|
41
|
+
: (unit -> 'value option) =
|
|
42
|
+
delayer
|
|
43
|
+
|
|
44
|
+
member inline _.Run([<InlineIfLambda>] delayed) = delayed ()
|
|
45
|
+
|
|
46
|
+
member inline this.TryWith([<InlineIfLambda>] computation, handler) : 'value =
|
|
47
|
+
try
|
|
48
|
+
this.Run computation
|
|
49
|
+
with e ->
|
|
50
|
+
handler e
|
|
51
|
+
|
|
52
|
+
member inline this.TryFinally([<InlineIfLambda>] computation, compensation) =
|
|
53
|
+
try
|
|
54
|
+
this.Run computation
|
|
55
|
+
finally
|
|
56
|
+
compensation ()
|
|
57
|
+
|
|
58
|
+
member inline this.Using
|
|
59
|
+
(
|
|
60
|
+
resource: 'disposable :> IDisposable,
|
|
61
|
+
[<InlineIfLambda>] binder: 'disposable -> 'value option
|
|
62
|
+
) : 'value option =
|
|
63
|
+
this.TryFinally(
|
|
64
|
+
(fun () -> binder resource),
|
|
65
|
+
(fun () ->
|
|
66
|
+
if not (obj.ReferenceEquals(resource, null)) then
|
|
67
|
+
resource.Dispose()
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
member inline this.While
|
|
72
|
+
(
|
|
73
|
+
[<InlineIfLambda>] guard: unit -> bool,
|
|
74
|
+
[<InlineIfLambda>] generator: unit -> unit option
|
|
75
|
+
) : unit option =
|
|
76
|
+
|
|
77
|
+
let mutable doContinue = true
|
|
78
|
+
let mutable result = Some()
|
|
79
|
+
|
|
80
|
+
while doContinue
|
|
81
|
+
&& guard () do
|
|
82
|
+
match generator () with
|
|
83
|
+
| Some() -> ()
|
|
84
|
+
| None ->
|
|
85
|
+
doContinue <- false
|
|
86
|
+
result <- None
|
|
87
|
+
|
|
88
|
+
result
|
|
89
|
+
|
|
90
|
+
member inline this.For
|
|
91
|
+
(
|
|
92
|
+
sequence: #seq<'value>,
|
|
93
|
+
[<InlineIfLambda>] binder: 'value -> unit option
|
|
94
|
+
) : unit option =
|
|
95
|
+
this.Using(
|
|
96
|
+
sequence.GetEnumerator(),
|
|
97
|
+
fun enum -> this.While(enum.MoveNext, this.Delay(fun () -> binder enum.Current))
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
member inline _.BindReturn
|
|
101
|
+
(
|
|
102
|
+
input: 'input option,
|
|
103
|
+
[<InlineIfLambda>] mapper: 'input -> 'output
|
|
104
|
+
) : 'output option =
|
|
105
|
+
Option.map mapper input
|
|
106
|
+
|
|
107
|
+
member inline _.BindReturn
|
|
108
|
+
(
|
|
109
|
+
x: 'input,
|
|
110
|
+
[<InlineIfLambda>] f: 'input -> 'output
|
|
111
|
+
) : 'output option =
|
|
112
|
+
Option.map f (Option.ofObj x)
|
|
113
|
+
|
|
114
|
+
member inline _.MergeSources
|
|
115
|
+
(
|
|
116
|
+
option1: 'left option,
|
|
117
|
+
option2: 'right option
|
|
118
|
+
) : ('left * 'right) option =
|
|
119
|
+
Option.zip option1 option2
|
|
120
|
+
|
|
121
|
+
/// <summary>
|
|
122
|
+
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
|
|
123
|
+
///
|
|
124
|
+
/// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder
|
|
125
|
+
/// </summary>
|
|
126
|
+
member inline _.Source(result: 'value option) : 'value option = result
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/// <summary>
|
|
130
|
+
/// Method lets us transform data types into our internal representation.
|
|
131
|
+
/// </summary>
|
|
132
|
+
member inline _.Source(vopt: 'value voption) : 'value option = Option.ofValueOption vopt
|
|
133
|
+
|
|
134
|
+
/// <summary>
|
|
135
|
+
/// The default instance of the `OptionBuilder` type.
|
|
136
|
+
/// </summary>
|
|
137
|
+
let option = OptionBuilder()
|
|
138
|
+
|
|
139
|
+
[<AutoOpen>]
|
|
140
|
+
module OptionExtensionsLower =
|
|
141
|
+
type OptionBuilder with
|
|
142
|
+
|
|
143
|
+
member inline _.Source(nullableObj: 'value when 'value: null) : 'value option =
|
|
144
|
+
Option.ofObj nullableObj
|
|
145
|
+
|
|
146
|
+
member inline _.Source(m: string) : string option = Option.ofObj m
|
|
147
|
+
|
|
148
|
+
member inline _.MergeSources
|
|
149
|
+
(
|
|
150
|
+
nullableObj1: 'left,
|
|
151
|
+
option2: 'right option
|
|
152
|
+
) : ('left * 'right) option =
|
|
153
|
+
Option.zip (Option.ofObj nullableObj1) option2
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
member inline _.MergeSources
|
|
157
|
+
(
|
|
158
|
+
option1: 'left option,
|
|
159
|
+
nullableObj2: 'right
|
|
160
|
+
) : ('left * 'right) option =
|
|
161
|
+
Option.zip (option1) (Option.ofObj nullableObj2)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
member inline _.MergeSources
|
|
165
|
+
(
|
|
166
|
+
nullableObj1: 'left,
|
|
167
|
+
nullableObj2: 'right
|
|
168
|
+
) : ('left * 'right) option =
|
|
169
|
+
Option.zip (Option.ofObj nullableObj1) (Option.ofObj nullableObj2)
|
|
170
|
+
|
|
171
|
+
[<AutoOpen>]
|
|
172
|
+
module OptionExtensions =
|
|
173
|
+
open System
|
|
174
|
+
|
|
175
|
+
type OptionBuilder with
|
|
176
|
+
|
|
177
|
+
/// <summary>
|
|
178
|
+
/// Needed to allow `for..in` and `for..do` functionality
|
|
179
|
+
/// </summary>
|
|
180
|
+
member inline _.Source(s: #seq<'value>) : #seq<'value> = s
|
|
181
|
+
|
|
182
|
+
/// <summary>
|
|
183
|
+
/// Method lets us transform data types into our internal representation.
|
|
184
|
+
/// </summary>
|
|
185
|
+
member inline _.Source(nullable: Nullable<'value>) : 'value option =
|
|
186
|
+
Option.ofNullable nullable
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { class_type } from "../fable-library-js.4.14.0/Reflection.js";
|
|
2
|
+
|
|
3
|
+
export class OptionCE_OptionBuilder {
|
|
4
|
+
constructor() {
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function OptionCE_OptionBuilder_$reflection() {
|
|
9
|
+
return class_type("FsToolkit.ErrorHandling.OptionCE.OptionBuilder", void 0, OptionCE_OptionBuilder);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function OptionCE_OptionBuilder_$ctor() {
|
|
13
|
+
return new OptionCE_OptionBuilder();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const OptionCE_option = OptionCE_OptionBuilder_$ctor();
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=OptionCE.fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["./OptionCE.fs"],"names":["\u0060\u0060.ctor\u0060\u0060"],"mappings":";;;;;;;;;;;;;;;\u002BBAwIiB,AAAAA","file":null,"sourcesContent":null,"sourceRoot":null}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
namespace FsToolkit.ErrorHandling.Operator.Option
|
|
2
|
+
|
|
3
|
+
open FsToolkit.ErrorHandling
|
|
4
|
+
|
|
5
|
+
/// <summary>
|
|
6
|
+
/// Operators for working with the <c>Option</c> type.
|
|
7
|
+
/// </summary>
|
|
8
|
+
[<AutoOpen>]
|
|
9
|
+
module Option =
|
|
10
|
+
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// Shorthand for <c>Option.map</c>
|
|
13
|
+
/// </summary>
|
|
14
|
+
/// <param name="input">The <c>Option</c> value to bind over.</param>
|
|
15
|
+
/// <param name="binder">The function to bind over the <c>Option</c> value.</param>
|
|
16
|
+
/// <returns>The result of binding the function over the <c>Option</c> value.</returns>
|
|
17
|
+
let inline (>>=)
|
|
18
|
+
(input: Option<'input>)
|
|
19
|
+
([<InlineIfLambda>] binder: 'input -> Option<'output>)
|
|
20
|
+
: Option<'output> =
|
|
21
|
+
Option.bind binder input
|