diff --git a/Sanchime.Functional/Core/Extensions/Option.cs b/Sanchime.Functional/Core/Extensions/Option.cs index 009a16d..18e99dd 100644 --- a/Sanchime.Functional/Core/Extensions/Option.cs +++ b/Sanchime.Functional/Core/Extensions/Option.cs @@ -1,3 +1,4 @@ +using System; using Sanchime.Functional.Core.Options; using Sanchime.Functional.Core.Products; @@ -49,12 +50,33 @@ public static class OptionExtension #region 应用函子 - public static Option Apply(this Option option, Func, R> apply, Option value) + public static Option Apply(this Option> option, Option value) => option.Match( None: () => Option.None, - Some: (func) => value.Match( + Some: (apply) => value.Match( None: () => Option.None, - Some: (val) => Option.Some(apply(value)))); + Some: (val) => Option.Some(apply(val)))); + + public static Option> Apply(this Option> option, Option value) + => option.Map(CurryingExtension.Curry).Apply(value); #endregion + + public static T GetOrElse(this Option option, T @default) + => option.Match(() => @default, (val) => val); + + public static T GetOrElse(this Option option, Func fallback) + => option.Match(() => fallback(), (val) => val); + + public static Task GetOrElse(this Option option, Func> fallback) + => option.Match(() => fallback(), (val) => TaskExtension.Async(val)); + + public static Option OrElse(this Option left, Option right) + => left.Match(() => right, (_) => left); + + public static Option OrElse(this Option left, Func> right) + => left.Match(() => right(), (_) => left); + + + } diff --git a/Sanchime.Functional/Core/Extensions/Task.cs b/Sanchime.Functional/Core/Extensions/Task.cs new file mode 100644 index 0000000..8a8666c --- /dev/null +++ b/Sanchime.Functional/Core/Extensions/Task.cs @@ -0,0 +1,37 @@ +using System; +namespace Sanchime.Functional.Core.Extensions; + +public static class TaskExtension +{ + public static Task Async(T value) + => Task.FromResult(value); + + #region 函子 + + public static Task Map(this Task @this, Func Faulted, Func Completed) + => @this.ContinueWith(val => val.Status == TaskStatus.Faulted ? Faulted(val.Exception!) : Completed(val.Result)); + + public static async Task Map(this Task @this, Func mapping) + => mapping(await @this.ConfigureAwait(false)); + + public static async Task Map(this Task @this, Func mapping) + { + await @this; + return mapping(); + } + + public static Task> Map(this Task @this, Func mapping) + => @this.Map(mapping.Curry()); + + #endregion + + public static async Task Apply(this Task> @this, Task task) + => (await @this.ConfigureAwait(false))(await task.ConfigureAwait(false)); + + public static Task> Apply(this Task> @this, Task task) + => @this.Map(CurryingExtension.Curry).Apply(task); + + + + +} diff --git a/Sanchime.Functional/Core/Options/Option.cs b/Sanchime.Functional/Core/Options/Option.cs index 4398612..d3cd9a9 100644 --- a/Sanchime.Functional/Core/Options/Option.cs +++ b/Sanchime.Functional/Core/Options/Option.cs @@ -82,6 +82,7 @@ public readonly struct Option : IEquatable, IEquatable public TResult Match(Func None, Func Some) => _isSome ? Some(_value) : None(); + public bool Equals(Option other) => this._isSome == other._isSome && (this._isNone || this._value!.Equals(other._value)); diff --git a/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.deps.json b/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.deps.json new file mode 100644 index 0000000..82c9819 --- /dev/null +++ b/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.deps.json @@ -0,0 +1,23 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v7.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v7.0": { + "Sanchime.Functional/1.0.0": { + "runtime": { + "Sanchime.Functional.dll": {} + } + } + } + }, + "libraries": { + "Sanchime.Functional/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.dll b/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.dll new file mode 100644 index 0000000..716eb24 Binary files /dev/null and b/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.dll differ diff --git a/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.pdb b/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.pdb new file mode 100644 index 0000000..885f3af Binary files /dev/null and b/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.pdb differ diff --git a/Sanchime.Functional/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs b/Sanchime.Functional/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs new file mode 100644 index 0000000..88ecc6e --- /dev/null +++ b/Sanchime.Functional/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v7.0", FrameworkDisplayName = "")] diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.AssemblyInfo.cs b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.AssemblyInfo.cs new file mode 100644 index 0000000..4feb04d --- /dev/null +++ b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.AssemblyInfo.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +[assembly: System.Reflection.AssemblyCompanyAttribute("Sanchime.Functional")] +[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] +[assembly: System.Reflection.AssemblyProductAttribute("Sanchime.Functional")] +[assembly: System.Reflection.AssemblyTitleAttribute("Sanchime.Functional")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] + +// 由 MSBuild WriteCodeFragment 类生成。 + diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.AssemblyInfoInputs.cache b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.AssemblyInfoInputs.cache new file mode 100644 index 0000000..54ae77e --- /dev/null +++ b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +1132520a32de11ff302b7fe56da971f09e88fb78 diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.GeneratedMSBuildEditorConfig.editorconfig b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..73b922c --- /dev/null +++ b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.GeneratedMSBuildEditorConfig.editorconfig @@ -0,0 +1,10 @@ +is_global = true +build_property.TargetFramework = net7.0 +build_property.TargetPlatformMinVersion = +build_property.UsingMicrosoftNETSdkWeb = +build_property.ProjectTypeGuids = +build_property.InvariantGlobalization = +build_property.PlatformNeutralAssembly = +build_property._SupportedPlatformList = Linux,macOS,Windows +build_property.RootNamespace = Sanchime.Functional +build_property.ProjectDir = /home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/ diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.GlobalUsings.g.cs b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.GlobalUsings.g.cs new file mode 100644 index 0000000..8578f3d --- /dev/null +++ b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +global using global::System; +global using global::System.Collections.Generic; +global using global::System.IO; +global using global::System.Linq; +global using global::System.Net.Http; +global using global::System.Threading; +global using global::System.Threading.Tasks; diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.assets.cache b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.assets.cache new file mode 100644 index 0000000..60e27cf Binary files /dev/null and b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.assets.cache differ diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.AssemblyReference.cache b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.AssemblyReference.cache new file mode 100644 index 0000000..e22e2d0 Binary files /dev/null and b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.AssemblyReference.cache differ diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.CoreCompileInputs.cache b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..e174995 --- /dev/null +++ b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +14ff64154b5d7a38f0fe0b94f6fa9545005d4e6f diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.FileListAbsolute.txt b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..f71ab32 --- /dev/null +++ b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.FileListAbsolute.txt @@ -0,0 +1,12 @@ +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.AssemblyReference.cache +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.GeneratedMSBuildEditorConfig.editorconfig +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.AssemblyInfoInputs.cache +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.AssemblyInfo.cs +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.csproj.CoreCompileInputs.cache +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.deps.json +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.dll +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/bin/Debug/net7.0/Sanchime.Functional.pdb +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.dll +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/Debug/net7.0/refint/Sanchime.Functional.dll +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.pdb +/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/Debug/net7.0/ref/Sanchime.Functional.dll diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.dll b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.dll new file mode 100644 index 0000000..716eb24 Binary files /dev/null and b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.dll differ diff --git a/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.pdb b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.pdb new file mode 100644 index 0000000..885f3af Binary files /dev/null and b/Sanchime.Functional/obj/Debug/net7.0/Sanchime.Functional.pdb differ diff --git a/Sanchime.Functional/obj/Debug/net7.0/ref/Sanchime.Functional.dll b/Sanchime.Functional/obj/Debug/net7.0/ref/Sanchime.Functional.dll new file mode 100644 index 0000000..e78a44a Binary files /dev/null and b/Sanchime.Functional/obj/Debug/net7.0/ref/Sanchime.Functional.dll differ diff --git a/Sanchime.Functional/obj/Debug/net7.0/refint/Sanchime.Functional.dll b/Sanchime.Functional/obj/Debug/net7.0/refint/Sanchime.Functional.dll new file mode 100644 index 0000000..e78a44a Binary files /dev/null and b/Sanchime.Functional/obj/Debug/net7.0/refint/Sanchime.Functional.dll differ diff --git a/Sanchime.Functional/obj/Sanchime.Functional.csproj.nuget.dgspec.json b/Sanchime.Functional/obj/Sanchime.Functional.csproj.nuget.dgspec.json new file mode 100644 index 0000000..1000666 --- /dev/null +++ b/Sanchime.Functional/obj/Sanchime.Functional.csproj.nuget.dgspec.json @@ -0,0 +1,60 @@ +{ + "format": 1, + "restore": { + "/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/Sanchime.Functional.csproj": {} + }, + "projects": { + "/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/Sanchime.Functional.csproj": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/Sanchime.Functional.csproj", + "projectName": "Sanchime.Functional", + "projectPath": "/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/Sanchime.Functional.csproj", + "packagesPath": "/home/sanchime/.nuget/packages/", + "outputPath": "/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/", + "projectStyle": "PackageReference", + "configFilePaths": [ + "/home/sanchime/.nuget/NuGet/NuGet.Config" + ], + "originalTargetFrameworks": [ + "net7.0" + ], + "sources": { + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net7.0": { + "targetAlias": "net7.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + } + }, + "frameworks": { + "net7.0": { + "targetAlias": "net7.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "/home/sanchime/dotnet/sdk/7.0.100-preview.3.22179.4/RuntimeIdentifierGraph.json" + } + } + } + } +} \ No newline at end of file diff --git a/Sanchime.Functional/obj/Sanchime.Functional.csproj.nuget.g.props b/Sanchime.Functional/obj/Sanchime.Functional.csproj.nuget.g.props new file mode 100644 index 0000000..87a059e --- /dev/null +++ b/Sanchime.Functional/obj/Sanchime.Functional.csproj.nuget.g.props @@ -0,0 +1,15 @@ + + + + True + NuGet + $(MSBuildThisFileDirectory)project.assets.json + /home/sanchime/.nuget/packages/ + /home/sanchime/.nuget/packages/ + PackageReference + 6.2.0 + + + + + \ No newline at end of file diff --git a/Sanchime.Functional/obj/Sanchime.Functional.csproj.nuget.g.targets b/Sanchime.Functional/obj/Sanchime.Functional.csproj.nuget.g.targets new file mode 100644 index 0000000..3dc06ef --- /dev/null +++ b/Sanchime.Functional/obj/Sanchime.Functional.csproj.nuget.g.targets @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Sanchime.Functional/obj/project.assets.json b/Sanchime.Functional/obj/project.assets.json new file mode 100644 index 0000000..86c04d2 --- /dev/null +++ b/Sanchime.Functional/obj/project.assets.json @@ -0,0 +1,65 @@ +{ + "version": 3, + "targets": { + "net7.0": {} + }, + "libraries": {}, + "projectFileDependencyGroups": { + "net7.0": [] + }, + "packageFolders": { + "/home/sanchime/.nuget/packages/": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/Sanchime.Functional.csproj", + "projectName": "Sanchime.Functional", + "projectPath": "/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/Sanchime.Functional.csproj", + "packagesPath": "/home/sanchime/.nuget/packages/", + "outputPath": "/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/", + "projectStyle": "PackageReference", + "configFilePaths": [ + "/home/sanchime/.nuget/NuGet/NuGet.Config" + ], + "originalTargetFrameworks": [ + "net7.0" + ], + "sources": { + "https://api.nuget.org/v3/index.json": {} + }, + "frameworks": { + "net7.0": { + "targetAlias": "net7.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + } + }, + "frameworks": { + "net7.0": { + "targetAlias": "net7.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "/home/sanchime/dotnet/sdk/7.0.100-preview.3.22179.4/RuntimeIdentifierGraph.json" + } + } + } +} \ No newline at end of file diff --git a/Sanchime.Functional/obj/project.nuget.cache b/Sanchime.Functional/obj/project.nuget.cache new file mode 100644 index 0000000..fe74c1a --- /dev/null +++ b/Sanchime.Functional/obj/project.nuget.cache @@ -0,0 +1,8 @@ +{ + "version": 2, + "dgSpecHash": "SFlPh821qi4GkLKqdQvlF3w70bJfiHdxPTcWjQz6sHNJrETehv6TShnFcPyYahMOhHW73n97cu5NcnOrJNHiSw==", + "success": true, + "projectFilePath": "/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/Sanchime.Functional.csproj", + "expectedPackageFiles": [], + "logs": [] +} \ No newline at end of file diff --git a/Sanchime.Functional/obj/project.packagespec.json b/Sanchime.Functional/obj/project.packagespec.json new file mode 100644 index 0000000..8caba5b --- /dev/null +++ b/Sanchime.Functional/obj/project.packagespec.json @@ -0,0 +1 @@ +"restore":{"projectUniqueName":"/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/Sanchime.Functional.csproj","projectName":"Sanchime.Functional","projectPath":"/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/Sanchime.Functional.csproj","outputPath":"/home/sanchime/桌面/Program/C#/Sanchime/Sanchime.Functional/obj/","projectStyle":"PackageReference","originalTargetFrameworks":["net7.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net7.0":{"targetAlias":"net7.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net7.0":{"targetAlias":"net7.0","imports":["net461","net462","net47","net471","net472","net48"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"/home/sanchime/dotnet/sdk/7.0.100-preview.3.22179.4/RuntimeIdentifierGraph.json"}} \ No newline at end of file diff --git a/Sanchime.Functional/obj/rider.project.restore.info b/Sanchime.Functional/obj/rider.project.restore.info new file mode 100644 index 0000000..aa2ab3c --- /dev/null +++ b/Sanchime.Functional/obj/rider.project.restore.info @@ -0,0 +1 @@ +16514907543498126 \ No newline at end of file