Skip to content

Commit

Permalink
Nullable.ValueNullable.GetValueOrDefault (#17504)
Browse files Browse the repository at this point in the history
* We are already checking `Nullable.HasValue` before accessing
  `Nullable.Value`, so it is safe to call `Nullable.GetValueOrDefault`,
  which does not do an additional check, unlike `Nullable.Value`.
  • Loading branch information
brianrourkeboll authored Aug 12, 2024
1 parent 6fac9b9 commit cff6266
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/FSharp.Core/option.fs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module Option =
[<CompiledName("OfNullable")>]
let inline ofNullable (value: System.Nullable<'T>) =
if value.HasValue then
Some value.Value
Some (value.GetValueOrDefault())
else
None

Expand Down Expand Up @@ -338,7 +338,7 @@ module ValueOption =
[<CompiledName("OfNullable")>]
let inline ofNullable (value: System.Nullable<'T>) =
if value.HasValue then
ValueSome value.Value
ValueSome (value.GetValueOrDefault())
else
ValueNone

Expand Down

0 comments on commit cff6266

Please sign in to comment.