-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
SelectNonNull extension method #24851
Comments
Thanks Thaina. It would be helpful to follow https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/api-review-process.md Also, it would be helpful to mention the most common use cases, and why it is specially needed in the framework, and not as a helper library to a few users who might use it. |
|
@jnm2 Interesting. But And it can't convert nullable to struct, which is the point of this proposal Also should we |
Why is this not just: .Select(func).Where(c => c != null) ? |
@stephentoub @Thaina seemed particularly interested in the unwrapping of nullable values (second overload). Equivalent of that one would be I have a |
@stephentoub It obviously shorter and reduce number of delegates |
Yes, that's true for any LINQ usage of multiple operators; you could always create a new operator that represented the combination. I'm not seeing why this particular combination is so valuable and generally in need by many developers that it would warrant a dedicated method. |
@stephentoub Because I think this is most common logic. To select something and also filtering at the same time. Without the need to pollute code with |
If we have a https://docs.microsoft.com/ja-jp/dotnet/csharp/tutorials/nullable-reference-types |
I ran into the same need when converting code base of a project to NRT. A pattern that keeps appearing in my code is: public IEnumerable<Guid> GetAllGuids1(IEnumerable<SomeClass> instances)
{
return instances
.Where(x => x.SomeGuid.HasValue)
.Select(x => x.SomeGuid!.Value);
}
public class SomeClass
{
public Guid? SomeGuid { get; set; }
public string? Name { get; set; }
} Couldn't find anything in the framework which would allow to easily convert from T? to T without the use of null-forgiving operator. Eliminating the need for ! is what makes this combination valuable. @stephentoub |
I don't think adding new LINQ APIs is the right way to address this. From my perspective, it should be done via language/compiler support. |
This is effectively a duplicate of #30381. Closing this one to focus the conversation. |
Could we have this in
System.Linq
?I don't know what name it should but this extension method is convenient
The text was updated successfully, but these errors were encountered: