添加Linq
This commit is contained in:
parent
75a2a3befa
commit
c26fb69188
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||||
|
// Use hover for the description of the existing attributes
|
||||||
|
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||||
|
"name": ".NET Core Launch (console)",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "build",
|
||||||
|
// If you have changed target frameworks, make sure to update the program path.
|
||||||
|
"program": "${workspaceFolder}/Sanchime.Test/bin/Debug/net7.0/Sanchime.Test.dll",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}/Sanchime.Test",
|
||||||
|
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||||
|
"console": "internalConsole",
|
||||||
|
"stopAtEntry": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": ".NET Core Attach",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "attach"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"${workspaceFolder}/Sanchime.Test/Sanchime.Test.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "publish",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"publish",
|
||||||
|
"${workspaceFolder}/Sanchime.Test/Sanchime.Test.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "watch",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"watch",
|
||||||
|
"run",
|
||||||
|
"--project",
|
||||||
|
"${workspaceFolder}/Sanchime.Test/Sanchime.Test.csproj"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -54,4 +54,31 @@ public static class ExceptionalException
|
||||||
=> @this.Map(CurryingExtension.CurryFirst).Apply(value);
|
=> @this.Map(CurryingExtension.CurryFirst).Apply(value);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region 单子
|
||||||
|
|
||||||
|
public static Exceptional<R> Bind<T, R>(this Exceptional<T> @this, Func<T, Exceptional<R>> binding)
|
||||||
|
=> @this.Successful ? binding(@this.Value) : new Exceptional<R>(@this.Exception);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public static Exceptional<Unit> ForEach<T>(this Exceptional<T> @this, Action<T> action)
|
||||||
|
=> @this.Map(action.ToFunc());
|
||||||
|
|
||||||
|
#region Linq
|
||||||
|
|
||||||
|
public static Exceptional<R> Select<T, R>(this Exceptional<T> @this, Func<T, R> mapping)
|
||||||
|
=> @this.Map(mapping);
|
||||||
|
|
||||||
|
public static Exceptional<RR> SelectMany<T, R, RR>(this Exceptional<T> @this, Func<T, Exceptional<R>> binding, Func<T, R, RR> project)
|
||||||
|
{
|
||||||
|
if (@this.Exceptionally)
|
||||||
|
{
|
||||||
|
return new Exceptional<RR>(@this.Exception);
|
||||||
|
}
|
||||||
|
var bound = binding(@this.Value);
|
||||||
|
return bound.Exceptionally ? new Exceptional<RR>(bound.Exception) : project(@this.Value, bound.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using Sanchime.Functional.Core.Products;
|
using Sanchime.Functional.Products;
|
||||||
using Sanchime.Functional.Core.Extensions;
|
using Sanchime.Functional.Extensions;
|
||||||
using Sanchime.Toolkits;
|
using Sanchime.Toolkits;
|
||||||
|
|
||||||
// Test<int> test = new Test<int>();
|
// Test<int> test = new Test<int>();
|
||||||
|
@ -19,15 +19,15 @@ using Sanchime.Toolkits;
|
||||||
|
|
||||||
// Option.Some(1).Map(x => (float)x + 1.2).Map(x => x.ToString()).Map(x => x.GetType().Name).WriteLine();
|
// Option.Some(1).Map(x => (float)x + 1.2).Map(x => x.ToString()).Map(x => x.GetType().Name).WriteLine();
|
||||||
|
|
||||||
// // 测试Option的Bind
|
// 测试Option的Bind
|
||||||
// var parse = (string s) => Int32.TryParse(s, out int i) ? Option.Some(i) : Option.None;
|
var parse = (string s) => Int32.TryParse(s, out int i) ? Option.Some(i) : Option.None;
|
||||||
// var foo = (string s) => s.Pipe(parse).Bind(Age.Of);
|
var foo = (string s) => s.Pipe(parse).Bind(Age.Of);
|
||||||
|
|
||||||
// foo("111").WriteLine();
|
foo("111").WriteLine();
|
||||||
// foo("aaa").WriteLine();
|
foo("aaa").WriteLine();
|
||||||
// foo("123").WriteLine();
|
foo("123").WriteLine();
|
||||||
// // 管道
|
// 管道
|
||||||
// foo("1ab").Pipe(x => Console.WriteLine(x));
|
foo("1ab").Pipe(x => Console.WriteLine(x));
|
||||||
public struct Age
|
public struct Age
|
||||||
{
|
{
|
||||||
private int _value;
|
private int _value;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Diagnostics;
|
||||||
namespace Sanchime.Toolkits;
|
namespace Sanchime.Toolkits;
|
||||||
|
|
||||||
public static class Basic
|
public static class Basic
|
||||||
|
@ -5,7 +6,7 @@ public static class Basic
|
||||||
|
|
||||||
public static void WriteLine<T>(this T @this)
|
public static void WriteLine<T>(this T @this)
|
||||||
{
|
{
|
||||||
System.Console.WriteLine(@this);
|
Debug.WriteLine(@this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteLine<T>(this T @this, Func<T, T> func)
|
public static void WriteLine<T>(this T @this, Func<T, T> func)
|
||||||
|
|
Loading…
Reference in New Issue