更新IEnumerable扩展

This commit is contained in:
Sanchime 2022-05-12 22:27:31 +08:00
parent 87d0931986
commit 3f61a327c1
1 changed files with 13 additions and 4 deletions

View File

@ -93,11 +93,20 @@ public static class IEnumerableExtension
public static IEnumerable<Unit> ForEach<T>(this IEnumerable<T> source, Action<T> action)
=> source.Map(action.ToFunc()).ToImmutableList();
public static IEnumerable<R> Bind<T, R>(this IEnumerable<T> source, Func<T, IEnumerable<R>> func)
=> source.SelectMany(func);
public static IEnumerable<R> Bind<T, R>(this IEnumerable<T> source, Func<T, IEnumerable<R>> binding)
=> source.SelectMany(binding);
public static IEnumerable<R> Bind<T, R>(this IEnumerable<T> source, Func<T, Option<R>> func)
=> source.Bind(t => func(t).AsEnumerable());
public static IEnumerable<R> Bind<T, R>(this IEnumerable<T> source, Func<T, Option<R>> binding)
=> source.Bind(val => binding(val).AsEnumerable());
/// <summary>
/// 将二级序列平展
/// </summary>
/// <param name="source"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static IEnumerable<T> Flatten<T>(this IEnumerable<IEnumerable<T>> source)
=> source.SelectMany(x => x);
private static IEnumerable<T> List<T>(T t)