Skip to content

Commit

Permalink
Expand Choose implementation (morelinq#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz authored May 1, 2019
1 parent 3351921 commit b06309d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions MoreLinq/Choose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ static partial class MoreEnumerable
/// </example>

public static IEnumerable<TResult> Choose<T, TResult>(this IEnumerable<T> source,
Func<T, (bool IsSome, TResult Value)> chooser)
Func<T, (bool, TResult)> 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<TResult> _()
{
foreach (var item in source)
{
var (some, value) = chooser(item);
if (some)
yield return value;
}
}
}
}
}
2 changes: 1 addition & 1 deletion MoreLinq/Extensions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public static partial class ChooseExtension
/// </example>

public static IEnumerable<TResult> Choose<T, TResult>(this IEnumerable<T> source,
Func<T, (bool IsSome, TResult Value)> chooser)
Func<T, (bool, TResult)> chooser)
=> MoreEnumerable.Choose(source, chooser);

}
Expand Down

0 comments on commit b06309d

Please sign in to comment.