Skip to content
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: Null-conditional forwarding operator #8593

Closed
alrz opened this issue Feb 11, 2016 · 2 comments
Closed

Proposal: Null-conditional forwarding operator #8593

alrz opened this issue Feb 11, 2016 · 2 comments

Comments

@alrz
Copy link
Contributor

alrz commented Feb 11, 2016

Given the forward pipe operator proposed in #5445, it has been suggested by @HaloFour to extend it with a variant that function like the null-propagation operator, as an alternative to #5961,

var result = Foo.Bar?.Baz ?> F() ?? false;
var result = Foo.Bar?.Baz != null ? F(Foo.Bar.Baz) : false;

The value forwarded to the target function F is of a non-nullable type (#5032).

Just like ?. operator, you don't need to use ?> if the target function doesn't return a nullable value, so for chaining you should use the regular |> operator to not perform an additional null-checking, e.g.

var result = nullable?.Foo.Bar;
var result = nullable ?> F() |> G();

In this example F takes a non-nullable and returns a non-nullable but the result will be a nullable if you don't use the ?? operator at the end.

@DavidArno
Copy link

Yes.

Not really much else to say :)

@gafter
Copy link
Member

gafter commented Feb 11, 2016

This issue is a proposal to modify a proposal described in an issue?

I don't think it belongs as a separate issue. Can you please record this suggestion in the context of the proposal that it applies to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants