You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi.
First off: reading the book at the moment and think it's great. Thank you.
I encountered a bug today when I tried to do this:
return Option<T>.Map(t => t.NullableA?.NullableB) // and either nullable A or B were null!
Creating a Some with a value of null threw an exception.
My first thought was 'why doesn't that just create a None instead of throwing' but then I realised Its because its within a constructor.
What would you recommend as a sensible replacement to the code above?
I replaced it with
return Option<T>.Match( Some: t => t.NullableA?.NullableB is null ? None : Some(b.NullableA?.NullableB), None:() => None);
I'm assuming I've misunderstood something.
Thanks
Dave
The text was updated successfully, but these errors were encountered:
Hi.
First off: reading the book at the moment and think it's great. Thank you.
I encountered a bug today when I tried to do this:
return Option<T>.Map(t => t.NullableA?.NullableB) // and either nullable A or B were null!
Creating a Some with a value of null threw an exception.
My first thought was 'why doesn't that just create a None instead of throwing' but then I realised Its because its within a constructor.
What would you recommend as a sensible replacement to the code above?
I replaced it with
return Option<T>.Match( Some: t => t.NullableA?.NullableB is null ? None : Some(b.NullableA?.NullableB), None:() => None);
I'm assuming I've misunderstood something.
Thanks
Dave
The text was updated successfully, but these errors were encountered: