@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,462 @@
|
|
|
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<'T> (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
|
+
/// <summary>
|
|
132
|
+
/// Flips around the option and result structures of an option that contains a result.
|
|
133
|
+
/// </summary>
|
|
134
|
+
/// <param name="opt">The option containing a result.</param>
|
|
135
|
+
/// <returns>A result containing an option.</returns>
|
|
136
|
+
let inline sequenceResult (opt: Result<'ok, 'error> option) : Result<'ok option, 'error> =
|
|
137
|
+
traverseResult id opt
|
|
138
|
+
|
|
139
|
+
#if !FABLE_COMPILER
|
|
140
|
+
/// <summary>
|
|
141
|
+
/// Tries to parse a string value into a specified type using the TryParse method of the type.
|
|
142
|
+
/// </summary>
|
|
143
|
+
/// <typeparam name="^value">The type to parse the string value into, if it has a <c>TryParse</c> function</typeparam>
|
|
144
|
+
/// <param name="valueToParse">The string value to parse.</param>
|
|
145
|
+
/// <returns>An option containing the parsed value if successful, or None if parsing fails.</returns>
|
|
146
|
+
let inline tryParse< ^value
|
|
147
|
+
when ^value: (static member TryParse: string * byref< ^value > -> bool)>
|
|
148
|
+
(valueToParse: string)
|
|
149
|
+
: ^value option =
|
|
150
|
+
let mutable output = Unchecked.defaultof< ^value>
|
|
151
|
+
|
|
152
|
+
let parsed =
|
|
153
|
+
(^value: (static member TryParse: string * byref< ^value > -> bool) (valueToParse,
|
|
154
|
+
&output))
|
|
155
|
+
|
|
156
|
+
match parsed with
|
|
157
|
+
| true -> Some output
|
|
158
|
+
| _ -> None
|
|
159
|
+
|
|
160
|
+
/// <summary>
|
|
161
|
+
/// Tries to get the value associated with the specified key from the dictionary.
|
|
162
|
+
/// </summary>
|
|
163
|
+
/// <param name="key">The key to look up in the dictionary.</param>
|
|
164
|
+
/// <param name="dictionary">The dictionary to search for the key.</param>
|
|
165
|
+
/// <typeparam name="^Dictionary">The type of the dictionary, assuming it has a <c>TryGetValue</c> member accessible</typeparam>
|
|
166
|
+
/// <returns>
|
|
167
|
+
/// An option containing the value associated with the key if it exists in the dictionary,
|
|
168
|
+
/// or None if the key does not exist.
|
|
169
|
+
/// </returns>
|
|
170
|
+
let inline tryGetValue (key: 'key) (dictionary: ^Dictionary) : ^value option =
|
|
171
|
+
let mutable output = Unchecked.defaultof< ^value>
|
|
172
|
+
|
|
173
|
+
let parsed =
|
|
174
|
+
(^Dictionary: (member TryGetValue: 'key * byref< ^value > -> bool) (dictionary,
|
|
175
|
+
key,
|
|
176
|
+
&output))
|
|
177
|
+
|
|
178
|
+
match parsed with
|
|
179
|
+
| true -> Some output
|
|
180
|
+
| false -> None
|
|
181
|
+
#endif
|
|
182
|
+
|
|
183
|
+
/// <summary>
|
|
184
|
+
/// Takes two options and returns a tuple of the pair or <c>None</c> if either are <c>None</c>
|
|
185
|
+
///
|
|
186
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/zip</href>
|
|
187
|
+
/// </summary>
|
|
188
|
+
/// <param name="left">The input option</param>
|
|
189
|
+
/// <param name="right">The input option</param>
|
|
190
|
+
/// <returns></returns>
|
|
191
|
+
let inline zip (left: 'left option) (right: 'right option) : ('left * 'right) option =
|
|
192
|
+
match left, right with
|
|
193
|
+
| Some v1, Some v2 -> Some(v1, v2)
|
|
194
|
+
| _ -> None
|
|
195
|
+
|
|
196
|
+
/// <summary>
|
|
197
|
+
/// Converts a <c>Result</c> to an <c>option</c>.
|
|
198
|
+
///
|
|
199
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/transforms/ofresult</href>
|
|
200
|
+
/// </summary>
|
|
201
|
+
/// <param name="r">The result to convert.</param>
|
|
202
|
+
/// <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>
|
|
203
|
+
let inline ofResult (r: Result<'ok, 'error>) : 'ok option =
|
|
204
|
+
match r with
|
|
205
|
+
| Ok v -> Some v
|
|
206
|
+
| Error _ -> None
|
|
207
|
+
|
|
208
|
+
/// <summary>
|
|
209
|
+
/// Convert a potentially null value to an option.
|
|
210
|
+
///
|
|
211
|
+
/// 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.
|
|
212
|
+
/// This is beneficial where third party APIs may generate a record type using reflection and it can be null.
|
|
213
|
+
/// 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.
|
|
214
|
+
///
|
|
215
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/transforms/ofnull</href>
|
|
216
|
+
/// </summary>
|
|
217
|
+
/// <param name="value">The potentially null value</param>
|
|
218
|
+
/// <returns>An option</returns>
|
|
219
|
+
/// <seealso cref="FSharp.Core.Option.ofObj"/>
|
|
220
|
+
let inline ofNull (value: 'nullableValue) : 'nullableValue option =
|
|
221
|
+
if System.Object.ReferenceEquals(value, null) then
|
|
222
|
+
None
|
|
223
|
+
else
|
|
224
|
+
Some value
|
|
225
|
+
|
|
226
|
+
/// <summary>
|
|
227
|
+
///
|
|
228
|
+
/// <c>bindNull binder option</c> evaluates to <c>match option with None -> None | Some x -> binder x |> Option.ofNull</c>
|
|
229
|
+
///
|
|
230
|
+
/// Automatically onverts the result of binder that is pontentially null into an option.
|
|
231
|
+
///
|
|
232
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/bindnull</href>
|
|
233
|
+
/// </summary>
|
|
234
|
+
/// <param name="binder">A function that takes the value of type 'value from an option and transforms it into
|
|
235
|
+
/// a value of type 'nullableValue.</param>
|
|
236
|
+
/// <param name="option">The input option</param>
|
|
237
|
+
/// <typeparam name="'value"></typeparam>
|
|
238
|
+
/// <typeparam name="'nullableValue"></typeparam>
|
|
239
|
+
/// <returns>An option of the output type of the binder.</returns>
|
|
240
|
+
/// <seealso cref="ofNull"/>
|
|
241
|
+
let inline bindNull
|
|
242
|
+
([<InlineIfLambda>] binder: 'value -> 'nullableValue)
|
|
243
|
+
(option: 'value option)
|
|
244
|
+
: 'nullableValue option =
|
|
245
|
+
match option with
|
|
246
|
+
| Some x ->
|
|
247
|
+
binder x
|
|
248
|
+
|> ofNull
|
|
249
|
+
| None -> None
|
|
250
|
+
|
|
251
|
+
/// <summary>
|
|
252
|
+
/// Returns result of running <paramref name="onSome"/> if it is <c>Some</c>, otherwise returns result of running <paramref name="onNone"/>
|
|
253
|
+
///
|
|
254
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/either</href>
|
|
255
|
+
/// </summary>
|
|
256
|
+
/// <param name="onSome">The function to run if <paramref name="input"/> is <c>Some</c></param>
|
|
257
|
+
/// <param name="onNone">The function to run if <paramref name="input"/> is <c>None</c></param>
|
|
258
|
+
/// <param name="input">The input option.</param>
|
|
259
|
+
/// <returns>
|
|
260
|
+
/// The result of running <paramref name="onSome"/> if the input is <c>Some</c>, else returns result of running <paramref name="onNone"/>.
|
|
261
|
+
/// </returns>
|
|
262
|
+
let inline either
|
|
263
|
+
([<InlineIfLambda>] onSome: 'a -> 'output)
|
|
264
|
+
([<InlineIfLambda>] onNone: unit -> 'output)
|
|
265
|
+
(input: 'a option)
|
|
266
|
+
: 'output =
|
|
267
|
+
match input with
|
|
268
|
+
| Some x -> onSome x
|
|
269
|
+
| None -> onNone ()
|
|
270
|
+
|
|
271
|
+
/// <summary>
|
|
272
|
+
/// If the option is <c>Some</c>, executes the function on the <c>Some</c> value and passes through the input value.
|
|
273
|
+
///
|
|
274
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/teefunctions#teesome</href>
|
|
275
|
+
/// </summary>
|
|
276
|
+
/// <param name="f">The function to execute on the <c>Some</c> value.</param>
|
|
277
|
+
/// <param name="opt">The input option.</param>
|
|
278
|
+
/// <returns>The input option</returns>
|
|
279
|
+
let inline teeSome ([<InlineIfLambda>] f: 'T -> unit) (opt: 'T option) : 'T option =
|
|
280
|
+
match opt with
|
|
281
|
+
| Some x -> f x
|
|
282
|
+
| None -> ()
|
|
283
|
+
|
|
284
|
+
opt
|
|
285
|
+
|
|
286
|
+
/// <summary>
|
|
287
|
+
/// If the option is <c>None</c>, executes the function and passes through the input value.
|
|
288
|
+
///
|
|
289
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/teefunctions#teenone</href>
|
|
290
|
+
/// </summary>
|
|
291
|
+
/// <param name="f">The function to execute if the input is <c>None</c>.</param>
|
|
292
|
+
/// <param name="opt">The input option.</param>
|
|
293
|
+
/// <returns>The input option</returns>
|
|
294
|
+
let inline teeNone (f: unit -> unit) (opt: 'T option) : 'T option =
|
|
295
|
+
match opt with
|
|
296
|
+
| Some _ -> ()
|
|
297
|
+
| None -> f ()
|
|
298
|
+
|
|
299
|
+
opt
|
|
300
|
+
|
|
301
|
+
/// <summary>
|
|
302
|
+
/// If the result is <c>Some</c> and the predicate returns true, executes the function
|
|
303
|
+
/// on the <c>Some</c> value and passes through the input value.
|
|
304
|
+
///
|
|
305
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/teefunctions#teeif</href>
|
|
306
|
+
/// </summary>
|
|
307
|
+
/// <param name="predicate">The predicate to execute on the <c>Some</c> value.</param>
|
|
308
|
+
/// <param name="f">The function to execute on the <c>Some</c> value if the predicate proves true</param>
|
|
309
|
+
/// <param name="opt">The input option.</param>
|
|
310
|
+
/// <returns>The input option</returns>
|
|
311
|
+
let inline teeIf
|
|
312
|
+
([<InlineIfLambda>] predicate: 'T -> bool)
|
|
313
|
+
([<InlineIfLambda>] f: 'T -> unit)
|
|
314
|
+
(opt: 'T option)
|
|
315
|
+
: 'T option =
|
|
316
|
+
match opt with
|
|
317
|
+
| Some x ->
|
|
318
|
+
if predicate x then
|
|
319
|
+
f x
|
|
320
|
+
| None -> ()
|
|
321
|
+
|
|
322
|
+
opt
|
|
323
|
+
|
|
324
|
+
#if !FABLE_COMPILER
|
|
325
|
+
open System.Threading.Tasks
|
|
326
|
+
|
|
327
|
+
/// <summary>
|
|
328
|
+
/// Converts an <c>Option<Task<_>></c> to an <c>Task<Option<_>></c><br />
|
|
329
|
+
///
|
|
330
|
+
/// Documentation is found here: <see href="https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/sequencetask" />
|
|
331
|
+
/// </summary>
|
|
332
|
+
let inline sequenceTask (optTask: Task<'T> option) : Task<'T option> =
|
|
333
|
+
task {
|
|
334
|
+
match optTask with
|
|
335
|
+
| Some tsk ->
|
|
336
|
+
let! x = tsk
|
|
337
|
+
return Some x
|
|
338
|
+
| None -> return None
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/// <summary>
|
|
342
|
+
/// Maps a <c>Task</c> function over an <c>option</c>, returning a <c>Task<'U option></c><br/>
|
|
343
|
+
///
|
|
344
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/traversetask</href>
|
|
345
|
+
/// </summary>
|
|
346
|
+
/// <param name="f">The function to map over the <c>option</c>.</param>
|
|
347
|
+
/// <param name="opt">The <c>option</c> to map over.</param>
|
|
348
|
+
/// <returns>A <c>Task<'U option></c> with the mapped value.</returns>
|
|
349
|
+
let inline traverseTask
|
|
350
|
+
([<InlineIfLambda>] f: 'T -> Task<'U>)
|
|
351
|
+
(opt: 'T option)
|
|
352
|
+
: Task<'U option> =
|
|
353
|
+
sequenceTask ((map f) opt)
|
|
354
|
+
|
|
355
|
+
/// <summary>
|
|
356
|
+
/// Converts an <c>Task<Result<'ok,'error>> option</c> to an <c>Task<Result<'ok option,'error>></c><br />
|
|
357
|
+
///
|
|
358
|
+
/// Documentation is found here: <see href="https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/sequencetaskresult" />
|
|
359
|
+
/// </summary>
|
|
360
|
+
let inline sequenceTaskResult
|
|
361
|
+
(optTaskResult: Task<Result<'T, 'E>> option)
|
|
362
|
+
: Task<Result<'T option, 'E>> =
|
|
363
|
+
task {
|
|
364
|
+
match optTaskResult with
|
|
365
|
+
| Some taskRes ->
|
|
366
|
+
let! xRes = taskRes
|
|
367
|
+
|
|
368
|
+
return
|
|
369
|
+
xRes
|
|
370
|
+
|> Result.map Some
|
|
371
|
+
| None -> return Ok None
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/// <summary>
|
|
375
|
+
/// Maps a <c>TaskResult</c> function over an <c>option</c>, returning a <c>Task<Result<'U option, 'E>></c>.<br />
|
|
376
|
+
///
|
|
377
|
+
/// Documentation is found here: <see href="https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/traversetaskresult" />
|
|
378
|
+
/// </summary>
|
|
379
|
+
/// <param name="f">The function to map over the <c>option</c>.</param>
|
|
380
|
+
/// <param name="opt">The <c>option</c> to map over.</param>
|
|
381
|
+
/// <returns>A <c>Task<Result<'U option, 'E>></c> with the mapped value.</returns>
|
|
382
|
+
let inline traverseTaskResult
|
|
383
|
+
([<InlineIfLambda>] f: 'T -> Task<Result<'U, 'E>>)
|
|
384
|
+
(opt: 'T option)
|
|
385
|
+
: Task<Result<'U option, 'E>> =
|
|
386
|
+
sequenceTaskResult ((map f) opt)
|
|
387
|
+
#endif
|
|
388
|
+
|
|
389
|
+
/// <summary>
|
|
390
|
+
/// Converts a Async<'T> option to an Async<'T option>
|
|
391
|
+
///
|
|
392
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/sequenceasync</href>
|
|
393
|
+
/// </summary>
|
|
394
|
+
let inline sequenceAsync (optAsync: Async<'T> option) : Async<'T option> =
|
|
395
|
+
async {
|
|
396
|
+
match optAsync with
|
|
397
|
+
| Some asnc ->
|
|
398
|
+
let! x = asnc
|
|
399
|
+
return Some x
|
|
400
|
+
| None -> return None
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/// <summary>
|
|
404
|
+
/// Maps an Async function over an Option, returning an Async Option.
|
|
405
|
+
///
|
|
406
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/traverseasync</href>
|
|
407
|
+
/// </summary>
|
|
408
|
+
/// <param name="f">The function to map over the Option.</param>
|
|
409
|
+
/// <param name="opt">The Option to map over.</param>
|
|
410
|
+
/// <returns>An <c>Async<'U option></c> with the mapped value.</returns>
|
|
411
|
+
let inline traverseAsync
|
|
412
|
+
([<InlineIfLambda>] f: 'T -> Async<'U>)
|
|
413
|
+
(opt: 'T option)
|
|
414
|
+
: Async<'U option> =
|
|
415
|
+
sequenceAsync ((map f) opt)
|
|
416
|
+
|
|
417
|
+
/// <summary>
|
|
418
|
+
/// Converts a Async<Result<'ok,'error>> option to an Async<Result<'ok option,'error>>
|
|
419
|
+
///
|
|
420
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/sequenceasyncresult</href>
|
|
421
|
+
/// </summary>
|
|
422
|
+
let inline sequenceAsyncResult
|
|
423
|
+
(optAsyncResult: Async<Result<'T, 'E>> option)
|
|
424
|
+
: Async<Result<'T option, 'E>> =
|
|
425
|
+
async {
|
|
426
|
+
match optAsyncResult with
|
|
427
|
+
| Some asncRes ->
|
|
428
|
+
let! xRes = asncRes
|
|
429
|
+
|
|
430
|
+
return
|
|
431
|
+
xRes
|
|
432
|
+
|> Result.map Some
|
|
433
|
+
| None -> return Ok None
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/// <summary>
|
|
437
|
+
/// Maps an AsyncResult function over an option, returning an AsyncResult option.
|
|
438
|
+
///
|
|
439
|
+
/// /// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/traverseasyncresult</href>
|
|
440
|
+
/// </summary>
|
|
441
|
+
/// <param name="f">The function to map over the Option.</param>
|
|
442
|
+
/// <param name="opt">The Option to map over.</param>
|
|
443
|
+
/// <returns>An AsyncResult Option with the mapped value.</returns>
|
|
444
|
+
let inline traverseAsyncResult
|
|
445
|
+
([<InlineIfLambda>] f: 'T -> Async<Result<'U, 'E>>)
|
|
446
|
+
(opt: 'T option)
|
|
447
|
+
: Async<Result<'U option, 'E>> =
|
|
448
|
+
sequenceAsyncResult ((map f) opt)
|
|
449
|
+
|
|
450
|
+
/// <summary>
|
|
451
|
+
/// Creates an option from a boolean value and a value of type 'a.
|
|
452
|
+
/// If the boolean value is true, returns <c>Some</c> value.
|
|
453
|
+
/// If the boolean value is false, returns <c>None</c>.
|
|
454
|
+
///
|
|
455
|
+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/option/transforms/ofpair</href>
|
|
456
|
+
/// </summary>
|
|
457
|
+
/// <param name="input">A tuple containing a boolean value and a value of type 'a.</param>
|
|
458
|
+
/// <returns>An option value.</returns>
|
|
459
|
+
let inline ofPair (input: bool * 'a) =
|
|
460
|
+
match input with
|
|
461
|
+
| true, x -> Some x
|
|
462
|
+
| false, _ -> None
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
namespace FsToolkit.ErrorHandling
|
|
2
|
+
|
|
3
|
+
[<AutoOpen>]
|
|
4
|
+
module OptionCE =
|
|
5
|
+
open System
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
type OptionBuilderBase() =
|
|
9
|
+
|
|
10
|
+
member inline _.Bind(x: 'b voption, [<InlineIfLambda>] f: 'b -> voption<'c>) : voption<'c> =
|
|
11
|
+
ValueOption.bind f x
|
|
12
|
+
|
|
13
|
+
member inline _.BindReturn(x: 'b voption, [<InlineIfLambda>] f: 'b -> 'c) : voption<'c> =
|
|
14
|
+
ValueOption.map f x
|
|
15
|
+
|
|
16
|
+
member inline _.Return(x: 'a) = ValueSome x
|
|
17
|
+
|
|
18
|
+
member inline _.ReturnFrom(x: 'a voption) = x
|
|
19
|
+
|
|
20
|
+
member inline _.Zero() = ValueSome()
|
|
21
|
+
|
|
22
|
+
member inline _.Delay([<InlineIfLambda>] f: unit -> voption<_>) = f
|
|
23
|
+
|
|
24
|
+
member inline _.Combine
|
|
25
|
+
(m: 'input voption, [<InlineIfLambda>] binder: 'input -> 'output voption)
|
|
26
|
+
: 'output voption =
|
|
27
|
+
ValueOption.bind binder m
|
|
28
|
+
|
|
29
|
+
member inline this.Combine(m1: unit voption, m2: 'output voption) : 'output voption =
|
|
30
|
+
this.Bind(m1, (fun () -> m2))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
member inline this.TryWith([<InlineIfLambda>] computation, handler) : 'value =
|
|
34
|
+
try
|
|
35
|
+
computation ()
|
|
36
|
+
with e ->
|
|
37
|
+
handler e
|
|
38
|
+
|
|
39
|
+
member inline this.TryFinally([<InlineIfLambda>] computation, compensation) =
|
|
40
|
+
try
|
|
41
|
+
computation ()
|
|
42
|
+
finally
|
|
43
|
+
compensation ()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
member inline this.Using
|
|
47
|
+
(
|
|
48
|
+
resource: 'disposable :> IDisposableNull,
|
|
49
|
+
[<InlineIfLambda>] binder: 'disposable -> 'value voption
|
|
50
|
+
) : 'value voption =
|
|
51
|
+
this.TryFinally(
|
|
52
|
+
(fun () -> binder resource),
|
|
53
|
+
(fun () ->
|
|
54
|
+
if not (obj.ReferenceEquals(resource, null)) then
|
|
55
|
+
resource.Dispose()
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
member inline this.While
|
|
60
|
+
(
|
|
61
|
+
[<InlineIfLambda>] guard: unit -> bool,
|
|
62
|
+
[<InlineIfLambda>] generator: unit -> unit voption
|
|
63
|
+
) : unit voption =
|
|
64
|
+
|
|
65
|
+
let mutable doContinue = true
|
|
66
|
+
let mutable result = ValueSome()
|
|
67
|
+
|
|
68
|
+
while doContinue
|
|
69
|
+
&& guard () do
|
|
70
|
+
match generator () with
|
|
71
|
+
| ValueSome() -> ()
|
|
72
|
+
| ValueNone ->
|
|
73
|
+
doContinue <- false
|
|
74
|
+
result <- ValueNone
|
|
75
|
+
|
|
76
|
+
result
|
|
77
|
+
|
|
78
|
+
member inline this.For
|
|
79
|
+
(sequence: #seq<'value> voption, [<InlineIfLambda>] binder: 'value -> unit voption)
|
|
80
|
+
: unit voption =
|
|
81
|
+
sequence
|
|
82
|
+
|> ValueOption.bind (fun sequence ->
|
|
83
|
+
this.Using(
|
|
84
|
+
sequence.GetEnumerator(),
|
|
85
|
+
fun enum ->
|
|
86
|
+
this.While(enum.MoveNext, this.Delay(fun () -> binder enum.Current))
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
[<AutoOpen>]
|
|
92
|
+
module BuilderExtensions =
|
|
93
|
+
type OptionBuilderBase with
|
|
94
|
+
member inline _.Source(o) = ValueOption.ofObj o
|
|
95
|
+
member inline _.Source(o: Nullable<'a>) = ValueOption.ofNullable o
|
|
96
|
+
|
|
97
|
+
[<AutoOpen>]
|
|
98
|
+
module BuilderExtensions3 =
|
|
99
|
+
type OptionBuilderBase with
|
|
100
|
+
/// <summary>
|
|
101
|
+
/// Needed to allow `for..in` and `for..do` functionality
|
|
102
|
+
/// </summary>
|
|
103
|
+
// member inline _.Source(s: string) = ValueOption.ofObj s
|
|
104
|
+
#if NET9_0_OR_GREATER && !FABLE_COMPILER
|
|
105
|
+
member inline _.Source(s: #seq<'value> | null) = ValueOption.ofObj s
|
|
106
|
+
#else
|
|
107
|
+
member inline _.Source(s: #seq<'value>) = ValueOption.ofNull s
|
|
108
|
+
#endif
|
|
109
|
+
|
|
110
|
+
type OptionBuilder() =
|
|
111
|
+
|
|
112
|
+
inherit OptionBuilderBase()
|
|
113
|
+
|
|
114
|
+
member inline _.Source(o: 'a option) = Option.toValueOption o
|
|
115
|
+
|
|
116
|
+
member inline _.Run(f) =
|
|
117
|
+
match f () with
|
|
118
|
+
| ValueSome x -> Some x
|
|
119
|
+
| ValueNone -> None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
type ValueOptionBuilder() =
|
|
123
|
+
|
|
124
|
+
inherit OptionBuilderBase()
|
|
125
|
+
|
|
126
|
+
member inline _.Source(o: 'a voption) = o
|
|
127
|
+
|
|
128
|
+
member inline _.Run(f) = f ()
|
|
129
|
+
|
|
130
|
+
[<AutoOpen>]
|
|
131
|
+
module OptionCEExtensions =
|
|
132
|
+
let option = OptionBuilder()
|
|
133
|
+
let voption = ValueOptionBuilder()
|
|
134
|
+
|
|
135
|
+
type ValueOptionBuilder with
|
|
136
|
+
member inline _.Source(o: 'a option) = Option.toValueOption o
|
|
137
|
+
|
|
138
|
+
type OptionBuilder with
|
|
139
|
+
member inline _.Source(o: 'a voption) = o
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
|
|
2
|
+
import { class_type } from "../fable-library-js.5.17.2/Reflection.js";
|
|
3
|
+
|
|
4
|
+
export class OptionBuilderBase {
|
|
5
|
+
constructor() {
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function OptionBuilderBase_$reflection() {
|
|
10
|
+
return class_type("FsToolkit.ErrorHandling.OptionCE.OptionBuilderBase", undefined, OptionBuilderBase);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function OptionBuilderBase_$ctor() {
|
|
14
|
+
return new OptionBuilderBase();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class OptionBuilder extends OptionBuilderBase {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function OptionBuilder_$reflection() {
|
|
24
|
+
return class_type("FsToolkit.ErrorHandling.OptionCE.OptionBuilder", undefined, OptionBuilder, OptionBuilderBase_$reflection());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function OptionBuilder_$ctor() {
|
|
28
|
+
return new OptionBuilder();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class ValueOptionBuilder extends OptionBuilderBase {
|
|
32
|
+
constructor() {
|
|
33
|
+
super();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function ValueOptionBuilder_$reflection() {
|
|
38
|
+
return class_type("FsToolkit.ErrorHandling.OptionCE.ValueOptionBuilder", undefined, ValueOptionBuilder, OptionBuilderBase_$reflection());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function ValueOptionBuilder_$ctor() {
|
|
42
|
+
return new ValueOptionBuilder();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const OptionCEExtensions_option = OptionBuilder_$ctor();
|
|
46
|
+
|
|
47
|
+
export const OptionCEExtensions_voption = ValueOptionBuilder_$ctor();
|
|
48
|
+
|
|
@@ -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: 'input option)
|
|
19
|
+
([<InlineIfLambda>] binder: 'input -> 'output option)
|
|
20
|
+
: 'output option =
|
|
21
|
+
Option.bind binder input
|