-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] WhereNotNull & SelectNotNull #784
Comments
WhereNotNull()
& SelectNotNull()
WhereNotNull()
& SelectNotNull()
I believe that this is a duplicate of #609, where I have presented arguments why IEnumerable<Person?> nullableList = new List<Person?> { new("Foo"), null, new("Bar")};
IEnumerable<Person> values = nullableList.Choose(Nullable.Deconstruct);
Debug.Assert(values.Count() == 2);
record Person(string Name);
static partial class Nullable
{
public static (bool HasValue, T Value) Deconstruct<T>(T? nullable) =>
nullable is not null ? (true, nullable) : default;
} Notice how the signature of I'll close this for now as a duplicate, but open to reconsidering if I've overlooked something. |
@atifaziz What you think of providing a |
@skarllot Why have another way to do the same thing?
It doesn't belong in MoreLINQ since it generally extends any type T whereas this library should only be extending sequential family of types like |
@atifaziz because it is a very common use case and avoid repeating the same code over and over. And about the null forgiving, the proposed Desconstruct is masquerading the null too as it returns |
Right, but MoreLINQ is not a convenience library of small helpers for common code. See the discussion in PR #1001 for some background.
True, but if you get a |
With C# 8 nullability feature it would be nice to be able to easily filter out null values.
I always use
For strict nullability warnings. Would be nice if we can have linq extensions that can automatically remove all null values and return a sequence of a non-nullable type.
The text was updated successfully, but these errors were encountered: