@glutinum/cli 0.14.0 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Glutinum.Converter/FsharpAST.js +38 -4
- package/dist/Glutinum.Converter/Generate.js +15 -7
- package/dist/Glutinum.Converter/GlueAST.js +45 -36
- package/dist/Glutinum.Converter/Hosting.js +918 -0
- package/dist/Glutinum.Converter/Merge.js +218 -82
- package/dist/Glutinum.Converter/Packages.js +44 -8
- package/dist/Glutinum.Converter/Printer.js +77 -49
- package/dist/Glutinum.Converter/Read.js +8 -8
- package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +7 -7
- package/dist/Glutinum.Converter/Reader/Declaration.js +26 -26
- package/dist/Glutinum.Converter/Reader/Documentation.js +37 -36
- package/dist/Glutinum.Converter/Reader/ExportAssignment.js +5 -5
- package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +31 -19
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +6 -7
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +36 -29
- package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +3 -3
- package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +82 -4
- package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +3 -3
- package/dist/Glutinum.Converter/Reader/Node.js +20 -20
- package/dist/Glutinum.Converter/Reader/Parameters.js +7 -7
- package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
- package/dist/Glutinum.Converter/Reader/TypeNode.js +291 -232
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +8 -8
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +108 -40
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +2 -2
- package/dist/Glutinum.Converter/Reader/Types.js +6 -6
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +7 -6
- package/dist/Glutinum.Converter/Reader/Utils.js +106 -56
- package/dist/Glutinum.Converter/Transform.js +2057 -700
- package/dist/Glutinum.Converter/TypeScript.Extensions.js +194 -202
- package/dist/Glutinum.Converter/Utils/Naming.js +7 -0
- package/dist/Glutinum.Converter/Utils/String.js +2 -2
- package/dist/Program.js +38 -26
- package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs +89 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs.js +105 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/Fable.Promise.fableproj +25 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs +842 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs.js +232 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs +31 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs +235 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs.js +384 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AssemblyInfo.fs +19 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs +287 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs.js +128 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOption.fs +127 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs +174 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs.js +37 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResult.fs +483 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs +201 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs +87 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs.js +26 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs +236 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidation.fs +185 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs +186 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationOp.fs +35 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/FsToolkit.ErrorHandling.fableproj +69 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs +276 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs.js +364 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Nullness.fs +81 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Option.fs +462 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs +139 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs.js +48 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionOp.fs +21 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs +88 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs.js +30 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs +200 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidation.fs +34 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs +244 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs +731 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs.js +45 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs +140 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs.js +23 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOp.fs +45 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs +201 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs.js +65 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs +135 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionOp.fs +57 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs +503 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs.js +295 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Validation.fs +167 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs +142 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationOp.fs +35 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueOption.fs +148 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOption.fs +102 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionCE.fs +587 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionOp.fs +10 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Array.js +1348 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Async.js +163 -0
- package/dist/fable_modules/fable-library-js.5.17.2/AsyncBuilder.js +204 -0
- package/dist/fable_modules/fable-library-js.5.17.2/BigInt.js +307 -0
- package/dist/fable_modules/fable-library-js.5.17.2/BitConverter.js +138 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Boolean.js +22 -0
- package/dist/fable_modules/fable-library-js.5.17.2/CHANGELOG.md +348 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Char.js +202 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Choice.js +184 -0
- package/dist/fable_modules/fable-library-js.5.17.2/CollectionUtil.js +182 -0
- package/dist/fable_modules/fable-library-js.5.17.2/ConditionalWeakTable.js +21 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Date.js +834 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateOffset.js +252 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateOnly.js +124 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateOnlyTemporal.js +146 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateTimeFormat.js +523 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateTimeOffsetTemporal.js +283 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateTimeTemporal.js +243 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Decimal.js +238 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Directory.js +11 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Double.js +53 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Encoding.js +185 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Environment.js +3 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Event.js +102 -0
- package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Collections.js +45 -0
- package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.CompilerServices.js +27 -0
- package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.js +156 -0
- package/dist/fable_modules/fable-library-js.5.17.2/File.js +27 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Global.js +29 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Guid.js +163 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Int32.js +135 -0
- package/dist/fable_modules/fable-library-js.5.17.2/List.js +1337 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Long.js +38 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MailboxProcessor.js +100 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Map.js +1400 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MapUtil.js +130 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MutableMap.js +339 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MutableSet.js +233 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Native.js +14 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Numeric.js +112 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Observable.js +115 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Option.js +87 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Path.js +31 -0
- package/dist/fable_modules/fable-library-js.5.17.2/README.md +3 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Random.js +172 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Range.js +45 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Reflection.js +489 -0
- package/dist/fable_modules/fable-library-js.5.17.2/RegExp.js +170 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Result.js +165 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Seq.js +1504 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Seq2.js +111 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Set.js +1829 -0
- package/dist/fable_modules/fable-library-js.5.17.2/String.js +731 -0
- package/dist/fable_modules/fable-library-js.5.17.2/System.Collections.Generic.js +333 -0
- package/dist/fable_modules/fable-library-js.5.17.2/System.Text.js +200 -0
- package/dist/fable_modules/fable-library-js.5.17.2/System.js +289 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Task.js +27 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TaskBuilder.js +72 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeOnly.js +122 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeOnlyTemporal.js +142 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeSpan.js +180 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeSpanTemporal.js +259 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Timer.js +67 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Types.js +198 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Unicode.13.0.0.js +4 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Uri.js +165 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Util.js +807 -0
- package/dist/fable_modules/fable-library-js.5.17.2/big.d.ts +338 -0
- package/dist/fable_modules/fable-library-js.5.17.2/lib/big.js +829 -0
- package/dist/fable_modules/fable-library-js.5.17.2/package.json +24 -0
- package/dist/fable_modules/fable-library-js.5.17.2/quotation.js +682 -0
- package/package.json +2 -2
- package/dist/Glutinum.Converter/TypeScript.js +0 -12
- package/src/Glutinum.Converter/js/bootstrap.js +0 -123
- package/src/Glutinum.Converter/js/host.js +0 -144
- package/src/Glutinum.Converter/js/npm.js +0 -137
- package/src/Glutinum.Converter/js/resolve.js +0 -402
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
namespace FsToolkit.ErrorHandling
|
|
2
|
+
|
|
3
|
+
[<RequireQualifiedAccess>]
|
|
4
|
+
module ValueOption =
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
let inline bind ([<InlineIfLambdaAttribute>] f) x =
|
|
8
|
+
match x with
|
|
9
|
+
| ValueSome v -> f v
|
|
10
|
+
| ValueNone -> ValueNone
|
|
11
|
+
|
|
12
|
+
let inline map ([<InlineIfLambdaAttribute>] f) x =
|
|
13
|
+
match x with
|
|
14
|
+
| ValueSome v -> ValueSome(f v)
|
|
15
|
+
| ValueNone -> ValueNone
|
|
16
|
+
|
|
17
|
+
let inline ofOption (opt: 'value option) : 'value voption =
|
|
18
|
+
match opt with
|
|
19
|
+
| Some v -> ValueSome v
|
|
20
|
+
| None -> ValueNone
|
|
21
|
+
|
|
22
|
+
let inline toOption (vopt: 'value voption) : 'value option =
|
|
23
|
+
match vopt with
|
|
24
|
+
| ValueSome v -> Some v
|
|
25
|
+
| ValueNone -> None
|
|
26
|
+
|
|
27
|
+
let inline traverseResult
|
|
28
|
+
([<InlineIfLambda>] binder: 'okInput -> Result<'okOutput, 'error>)
|
|
29
|
+
(input: 'okInput voption)
|
|
30
|
+
: Result<'okOutput voption, 'error> =
|
|
31
|
+
match input with
|
|
32
|
+
| ValueNone -> Ok ValueNone
|
|
33
|
+
| ValueSome v ->
|
|
34
|
+
binder v
|
|
35
|
+
|> Result.map ValueSome
|
|
36
|
+
|
|
37
|
+
let inline sequenceResult
|
|
38
|
+
(opt: Result<'okOutput, 'error> voption)
|
|
39
|
+
: Result<'okOutput voption, 'error> =
|
|
40
|
+
traverseResult id opt
|
|
41
|
+
|
|
42
|
+
let inline tryParse< ^value
|
|
43
|
+
when ^value: (static member TryParse: string * byref< ^value > -> bool)>
|
|
44
|
+
(valueToParse: string)
|
|
45
|
+
: ^value voption =
|
|
46
|
+
let mutable output = Unchecked.defaultof< ^value>
|
|
47
|
+
|
|
48
|
+
let parsed =
|
|
49
|
+
(^value: (static member TryParse: string * byref< ^value > -> bool) (valueToParse,
|
|
50
|
+
&output))
|
|
51
|
+
|
|
52
|
+
match parsed with
|
|
53
|
+
| true -> ValueSome output
|
|
54
|
+
| _ -> ValueNone
|
|
55
|
+
|
|
56
|
+
let inline tryGetValue (key: 'key) (dictionary: ^Dictionary) : ^value voption =
|
|
57
|
+
let mutable output = Unchecked.defaultof< ^value>
|
|
58
|
+
|
|
59
|
+
let parsed =
|
|
60
|
+
(^Dictionary: (member TryGetValue: 'key * byref< ^value > -> bool) (dictionary,
|
|
61
|
+
key,
|
|
62
|
+
&output))
|
|
63
|
+
|
|
64
|
+
match parsed with
|
|
65
|
+
| true -> ValueSome output
|
|
66
|
+
| false -> ValueNone
|
|
67
|
+
|
|
68
|
+
/// <summary>
|
|
69
|
+
/// Takes two voptions and returns a tuple of the pair or none if either are none
|
|
70
|
+
/// </summary>
|
|
71
|
+
/// <param name="voption1">The input option</param>
|
|
72
|
+
/// <param name="voption2">The input option</param>
|
|
73
|
+
/// <returns></returns>
|
|
74
|
+
let inline zip (left: 'left voption) (right: 'right voption) : ('left * 'right) voption =
|
|
75
|
+
match left, right with
|
|
76
|
+
| ValueSome v1, ValueSome v2 -> ValueSome(v1, v2)
|
|
77
|
+
| _ -> ValueNone
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
let inline ofResult (result: Result<'ok, 'error>) : 'ok voption =
|
|
81
|
+
match result with
|
|
82
|
+
| Ok v -> ValueSome v
|
|
83
|
+
| Error _ -> ValueNone
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
/// <summary>
|
|
87
|
+
/// Convert a potentially null value to an ValueOption.
|
|
88
|
+
///
|
|
89
|
+
/// This is different from <see cref="FSharp.Core.ValueOption.ofObj">ValueOption.ofObj</see> where it doesn't require the value to be constrained to null.
|
|
90
|
+
/// This is beneficial where third party APIs may generate a record type using reflection and it can be null.
|
|
91
|
+
/// 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.
|
|
92
|
+
/// </summary>
|
|
93
|
+
/// <param name="value">The potentially null value</param>
|
|
94
|
+
/// <returns>An ValueOption</returns>
|
|
95
|
+
/// <seealso cref="FSharp.Core.ValueOption.ofObj"/>
|
|
96
|
+
let inline ofNull (value: 'nullableValue) =
|
|
97
|
+
if System.Object.ReferenceEquals(value, null) then
|
|
98
|
+
ValueNone
|
|
99
|
+
else
|
|
100
|
+
ValueSome value
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
/// <summary>
|
|
104
|
+
///
|
|
105
|
+
/// <c>bindNull binder voption</c> evaluates to <c>match voption with ValueNone -> ValueNone | ValueSome x -> binder x |> ValueOption.ofNull</c>
|
|
106
|
+
///
|
|
107
|
+
/// Automatically onverts the result of binder that is pontentially null into an Valueoption.
|
|
108
|
+
/// </summary>
|
|
109
|
+
/// <param name="binder">A function that takes the value of type 'value from an voption and transforms it into
|
|
110
|
+
/// a value of type 'nullableValue.</param>
|
|
111
|
+
/// <param name="voption">The input voption</param>
|
|
112
|
+
/// <typeparam name="'value"></typeparam>
|
|
113
|
+
/// <typeparam name="'nullableValue"></typeparam>
|
|
114
|
+
/// <returns>A voption of the output type of the binder.</returns>
|
|
115
|
+
/// <seealso cref="ofNull"/>
|
|
116
|
+
let inline bindNull
|
|
117
|
+
([<InlineIfLambda>] binder: 'value -> 'nullableValue)
|
|
118
|
+
(voption: 'value voption)
|
|
119
|
+
: 'nullableValue voption =
|
|
120
|
+
match voption with
|
|
121
|
+
| ValueSome x ->
|
|
122
|
+
binder x
|
|
123
|
+
|> ofNull
|
|
124
|
+
| ValueNone -> ValueNone
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
/// <summary>
|
|
128
|
+
/// Returns result of running <paramref name="onSome"/> if it is <c>ValueSome</c>, otherwise returns result of running <paramref name="onNone"/>
|
|
129
|
+
/// </summary>
|
|
130
|
+
/// <param name="onSome">The function to run if <paramref name="input"/> is <c>ValueSome</c></param>
|
|
131
|
+
/// <param name="onNone">The function to run if <paramref name="input"/> is <c>ValueNone</c></param>
|
|
132
|
+
/// <param name="input">The input option.</param>
|
|
133
|
+
/// <returns>
|
|
134
|
+
/// The result of running <paramref name="onSome"/> if the input is <c>ValueSome</c>, else returns result of running <paramref name="onNone"/>.
|
|
135
|
+
/// </returns>
|
|
136
|
+
let inline either
|
|
137
|
+
([<InlineIfLambda>] onSome: 'a -> 'output)
|
|
138
|
+
([<InlineIfLambda>] onNone: unit -> 'output)
|
|
139
|
+
(input: 'a voption)
|
|
140
|
+
: 'output =
|
|
141
|
+
match input with
|
|
142
|
+
| ValueSome x -> onSome x
|
|
143
|
+
| ValueNone -> onNone ()
|
|
144
|
+
|
|
145
|
+
let inline ofPair (input: bool * 'a) =
|
|
146
|
+
match input with
|
|
147
|
+
| true, x -> ValueSome x
|
|
148
|
+
| false, _ -> ValueNone
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
namespace FsToolkit.ErrorHandling
|
|
2
|
+
|
|
3
|
+
open System.Threading.Tasks
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[<RequireQualifiedAccess>]
|
|
7
|
+
module ValueTaskValueOption =
|
|
8
|
+
|
|
9
|
+
let inline map ([<InlineIfLambda>] f) (ar: ValueTask<_ voption>) =
|
|
10
|
+
ValueTask<_ voption>(
|
|
11
|
+
task {
|
|
12
|
+
let! opt = ar
|
|
13
|
+
return ValueOption.map f opt
|
|
14
|
+
}
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
let inline bind ([<InlineIfLambda>] f) (ar: ValueTask<_ voption>) =
|
|
18
|
+
ValueTask<_ voption>(
|
|
19
|
+
task {
|
|
20
|
+
let! opt = ar
|
|
21
|
+
|
|
22
|
+
let t =
|
|
23
|
+
match opt with
|
|
24
|
+
| ValueSome x -> f x
|
|
25
|
+
| ValueNone -> ValueTask<_ voption>(ValueNone)
|
|
26
|
+
|
|
27
|
+
return! t
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
let inline valueSome x = ValueTask<_ voption>(ValueSome x)
|
|
32
|
+
|
|
33
|
+
let inline apply f x =
|
|
34
|
+
bind (fun f' -> bind (fun x' -> valueSome (f' x')) x) f
|
|
35
|
+
|
|
36
|
+
let inline zip (x1: ValueTask<'a voption>) (x2: ValueTask<'b voption>) =
|
|
37
|
+
ValueTask<('a * 'b) voption>(
|
|
38
|
+
task {
|
|
39
|
+
let! r1 = x1
|
|
40
|
+
let! r2 = x2
|
|
41
|
+
return ValueOption.zip r1 r2
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
/// <summary>
|
|
46
|
+
/// Returns result of running <paramref name="onValueSome"/> if it is <c>ValueSome</c>, otherwise returns result of running <paramref name="onValueNone"/>
|
|
47
|
+
/// </summary>
|
|
48
|
+
/// <param name="onValueSome">The function to run if <paramref name="input"/> is <c>ValueSome</c></param>
|
|
49
|
+
/// <param name="onValueNone">The function to run if <paramref name="input"/> is <c>ValueNone</c></param>
|
|
50
|
+
/// <param name="input">The input voption.</param>
|
|
51
|
+
/// <returns>
|
|
52
|
+
/// The result of running <paramref name="onValueSome"/> if the input is <c>ValueSome</c>, else returns result of running <paramref name="onValueNone"/>.
|
|
53
|
+
/// </returns>
|
|
54
|
+
let inline either
|
|
55
|
+
([<InlineIfLambda>] onValueSome: 'input -> ValueTask<'output>)
|
|
56
|
+
([<InlineIfLambda>] onValueNone: unit -> ValueTask<'output>)
|
|
57
|
+
(input: ValueTask<'input voption>)
|
|
58
|
+
: ValueTask<'output> =
|
|
59
|
+
ValueTask<'output>(
|
|
60
|
+
task {
|
|
61
|
+
let! opt = input
|
|
62
|
+
|
|
63
|
+
match opt with
|
|
64
|
+
| ValueSome v -> return! onValueSome v
|
|
65
|
+
| ValueNone -> return! onValueNone ()
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
/// <summary>
|
|
70
|
+
/// Gets the value of the voption if the voption is <c>ValueSome</c>, otherwise returns the specified default value.
|
|
71
|
+
/// </summary>
|
|
72
|
+
/// <param name="value">The specified default value.</param>
|
|
73
|
+
/// <param name="valueTaskValueOption">The input voption.</param>
|
|
74
|
+
/// <returns>
|
|
75
|
+
/// The voption if the voption is <c>ValueSome</c>, else the default value.
|
|
76
|
+
/// </returns>
|
|
77
|
+
let inline defaultValue (value: 'value) (valueTaskValueOption: ValueTask<'value voption>) =
|
|
78
|
+
ValueTask<'value>(
|
|
79
|
+
task {
|
|
80
|
+
let! opt = valueTaskValueOption
|
|
81
|
+
return ValueOption.defaultValue value opt
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
/// <summary>
|
|
86
|
+
/// Gets the value of the voption if the voption is <c>ValueSome</c>, otherwise evaluates <paramref name="defThunk"/> and returns the result.
|
|
87
|
+
/// </summary>
|
|
88
|
+
/// <param name="defThunk">A thunk that provides a default value when evaluated.</param>
|
|
89
|
+
/// <param name="valueTaskValueOption">The input voption.</param>
|
|
90
|
+
/// <returns>
|
|
91
|
+
/// The voption if the voption is <c>ValueSome</c>, else the result of evaluating <paramref name="defThunk"/>.
|
|
92
|
+
/// </returns>
|
|
93
|
+
let inline defaultWith
|
|
94
|
+
([<InlineIfLambda>] defThunk: unit -> 'value)
|
|
95
|
+
(valueTaskValueOption: ValueTask<'value voption>)
|
|
96
|
+
: ValueTask<'value> =
|
|
97
|
+
ValueTask<'value>(
|
|
98
|
+
task {
|
|
99
|
+
let! opt = valueTaskValueOption
|
|
100
|
+
return ValueOption.defaultWith defThunk opt
|
|
101
|
+
}
|
|
102
|
+
)
|