diff --git a/MoreLinq/Choose.cs b/MoreLinq/Choose.cs index 3d5ea7de8..52822e584 100644 --- a/MoreLinq/Choose.cs +++ b/MoreLinq/Choose.cs @@ -51,16 +51,20 @@ static partial class MoreEnumerable /// public static IEnumerable Choose(this IEnumerable source, - Func chooser) + Func chooser) { if (source == null) throw new ArgumentNullException(nameof(source)); if (chooser == null) throw new ArgumentNullException(nameof(chooser)); - return - from item in source - select chooser(item) into e - where e.IsSome - select e.Value; + return _(); IEnumerable _() + { + foreach (var item in source) + { + var (some, value) = chooser(item); + if (some) + yield return value; + } + } } } } diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index 94df8b96e..e1927ea37 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -744,7 +744,7 @@ public static partial class ChooseExtension /// public static IEnumerable Choose(this IEnumerable source, - Func chooser) + Func chooser) => MoreEnumerable.Choose(source, chooser); }