From e8a5dd982d9532c03781a8873beb5d4cbf9d07db Mon Sep 17 00:00:00 2001 From: Sanchime Date: Fri, 13 May 2022 21:37:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Append=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sanchime.Functional/Extensions/Either.cs | 2 ++ Sanchime.Functional/Extensions/IEnumerable.cs | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Sanchime.Functional/Extensions/Either.cs b/Sanchime.Functional/Extensions/Either.cs index ee61f21..bbd27c0 100644 --- a/Sanchime.Functional/Extensions/Either.cs +++ b/Sanchime.Functional/Extensions/Either.cs @@ -64,4 +64,6 @@ public static class EitherExtension public static Either ForEach(this Either either, Action action) => either.Map(action.ToFunc()); + + } diff --git a/Sanchime.Functional/Extensions/IEnumerable.cs b/Sanchime.Functional/Extensions/IEnumerable.cs index c2ead6e..ccb30dc 100644 --- a/Sanchime.Functional/Extensions/IEnumerable.cs +++ b/Sanchime.Functional/Extensions/IEnumerable.cs @@ -108,6 +108,32 @@ public static class IEnumerableExtension public static IEnumerable Flatten(this IEnumerable> source) => source.SelectMany(x => x); + public static IEnumerable DropWhile(this IEnumerable source, Func predicate) + { + bool cleaned = true; + foreach (var item in source) + { + if (!cleaned && !predicate(item)) + { + yield return item; + cleaned = false; + } + } + } + + public static IEnumerable Append(this IEnumerable source, params T[] list) + => source.Concat(list); + + public static IEnumerable Prepend(this IEnumerable source, T value) + { + yield return value; + foreach (var item in source) + { + yield return item; + } + } + + private static IEnumerable List(params T[] list) => list.ToImmutableList();