添加Linq
This commit is contained in:
parent
bd9392ec50
commit
7fbb363176
|
@ -72,4 +72,17 @@ public static class FreeMonad
|
|||
|
||||
internal static Free<T> More<T>(Coyo<object, Free<T>> value)
|
||||
=> new More<T>(value);
|
||||
|
||||
#region Linq
|
||||
|
||||
public static Free<R> Select<T, R>(this Free<T> @this, Func<T, R> mapping)
|
||||
=> @this.Match(val => Done<R>(mapping(val)), op => More(op.Map(free => free.Select(mapping))));
|
||||
|
||||
public static Free<R> SelectMany<T, R>(this Free<T> @this, Func<T, Free<R>> binding)
|
||||
=> @this.Match(binding, op => More(op.Map(free => free.SelectMany(binding))));
|
||||
|
||||
public static Free<RR> SelectMany<T, R, RR>(this Free<T> @this, Func<T, Free<R>> binding, Func<T, R, RR> project)
|
||||
=> @this.SelectMany(val => Select(binding(val), res => project(val, res)));
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue