完善Option, 新增加了一些Apply方法的重载
This commit is contained in:
parent
d50e84cbbd
commit
bc275bae7c
|
@ -58,6 +58,27 @@ public static class OptionExtension
|
||||||
public static Option<Func<T2, R>> Apply<T1, T2, R>(this Option<Func<T1, T2, R>> option, Option<T1> value)
|
public static Option<Func<T2, R>> Apply<T1, T2, R>(this Option<Func<T1, T2, R>> option, Option<T1> value)
|
||||||
=> option.Map(CurryingExtension.Curry).Apply(value);
|
=> option.Map(CurryingExtension.Curry).Apply(value);
|
||||||
|
|
||||||
|
public static Option<Func<T2, T3, R>> Apply<T1, T2, T3, R>(this Option<Func<T1, T2, T3, R>> option, Option<T1> value)
|
||||||
|
=> option.Map(CurryingExtension.CurryFirst).Apply(value);
|
||||||
|
|
||||||
|
public static Option<Func<T2, T3, T4, R>> Apply<T1, T2, T3, T4, R>(this Option<Func<T1, T2, T3, T4, R>> option, Option<T1> value)
|
||||||
|
=> option.Map(CurryingExtension.CurryFirst).Apply(value);
|
||||||
|
|
||||||
|
public static Option<Func<T2, T3, T4, T5, R>> Apply<T1, T2, T3, T4, T5, R>(this Option<Func<T1, T2, T3, T4, T5, R>> option, Option<T1> value)
|
||||||
|
=> option.Map(CurryingExtension.CurryFirst).Apply(value);
|
||||||
|
|
||||||
|
public static Option<Func<T2, T3, T4, T5, T6, R>> Apply<T1, T2, T3, T4, T5, T6, R>(this Option<Func<T1, T2, T3, T4, T5, T6, R>> option, Option<T1> value)
|
||||||
|
=> option.Map(CurryingExtension.CurryFirst).Apply(value);
|
||||||
|
|
||||||
|
public static Option<Func<T2, T3, T4, T5, T6, T7, R>> Apply<T1, T2, T3, T4, T5, T6, T7, R>(this Option<Func<T1, T2, T3, T4, T5, T6, T7, R>> option, Option<T1> value)
|
||||||
|
=> option.Map(CurryingExtension.CurryFirst).Apply(value);
|
||||||
|
|
||||||
|
public static Option<Func<T2, T3, T4, T5, T6, T7, T8, R>> Apply<T1, T2, T3, T4, T5, T6, T7, T8, R>(this Option<Func<T1, T2, T3, T4, T5, T6, T7, T8, R>> option, Option<T1> value)
|
||||||
|
=> option.Map(CurryingExtension.CurryFirst).Apply(value);
|
||||||
|
|
||||||
|
public static Option<Func<T2, T3, T4, T5, T6, T7, T8, T9, R>> Apply<T1, T2, T3, T4, T5, T6, T7, T8, T9, R>(this Option<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, R>> option, Option<T1> value)
|
||||||
|
=> option.Map(CurryingExtension.CurryFirst).Apply(value);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static T GetOrElse<T>(this Option<T> option, T @default)
|
public static T GetOrElse<T>(this Option<T> option, T @default)
|
||||||
|
|
|
@ -17,15 +17,17 @@ using Sanchime.Toolkits;
|
||||||
// res.WriteLine();
|
// res.WriteLine();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// 测试Option的Bind
|
// Option.Some(1).Map(x => (float)x + 1.2).Map(x => x.ToString()).Map(x => x.GetType().Name).WriteLine();
|
||||||
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);
|
|
||||||
|
|
||||||
foo("111").WriteLine();
|
// // 测试Option的Bind
|
||||||
foo("aaa").WriteLine();
|
// var parse = (string s) => Int32.TryParse(s, out int i) ? Option.Some(i) : Option.None;
|
||||||
foo("123").WriteLine();
|
// var foo = (string s) => s.Pipe(parse).Bind(Age.Of);
|
||||||
// 管道
|
|
||||||
foo("1ab").Pipe(x => Console.WriteLine(x));
|
// foo("111").WriteLine();
|
||||||
|
// foo("aaa").WriteLine();
|
||||||
|
// foo("123").WriteLine();
|
||||||
|
// // 管道
|
||||||
|
// foo("1ab").Pipe(x => Console.WriteLine(x));
|
||||||
public struct Age
|
public struct Age
|
||||||
{
|
{
|
||||||
private int _value;
|
private int _value;
|
||||||
|
|
Loading…
Reference in New Issue