添加Append方法

This commit is contained in:
Sanchime 2022-05-13 21:37:58 +08:00
parent 432cdf0045
commit e8a5dd982d
2 changed files with 28 additions and 0 deletions

View File

@ -64,4 +64,6 @@ public static class EitherExtension
public static Either<L, Unit> ForEach<L, R>(this Either<L, R> either, Action<R> action)
=> either.Map(action.ToFunc());
}

View File

@ -108,6 +108,32 @@ public static class IEnumerableExtension
public static IEnumerable<T> Flatten<T>(this IEnumerable<IEnumerable<T>> source)
=> source.SelectMany(x => x);
public static IEnumerable<T> DropWhile<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
bool cleaned = true;
foreach (var item in source)
{
if (!cleaned && !predicate(item))
{
yield return item;
cleaned = false;
}
}
}
public static IEnumerable<T> Append<T>(this IEnumerable<T> source, params T[] list)
=> source.Concat(list);
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T value)
{
yield return value;
foreach (var item in source)
{
yield return item;
}
}
private static IEnumerable<T> List<T>(params T[] list)
=> list.ToImmutableList();