Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/FSharpPlus/Extensions/Obj.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ module Obj =
/// <param name="source">The source object.</param>
/// <returns>The source if it is not null; otherwise, the specified default value.</returns>
/// <remarks>The default value is evaluated eagerly.</remarks>
#if NET9_0_OR_GREATER && !FABLE_COMPILER
let defaultValue value (source: 'T | null) : 'T =
#else
let defaultValue value (source: 'T) : 'T =
#endif
match source with
| null -> value
| value -> value
Expand All @@ -19,7 +23,11 @@ module Obj =
/// <param name="source">The source object.</param>
/// <returns>The source if it is not null; otherwise, the result of invoking the specified function.</returns>
/// <remarks>The fNull function is only invoked if the source is null.</remarks>
#if NET9_0_OR_GREATER && !FABLE_COMPILER
let inline defaultWith ([<InlineIfLambda>]fNull: unit -> 'T) (source: 'T | null) : 'T =
#else
let inline defaultWith ([<InlineIfLambda>]fNull: unit -> 'T) (source: 'T) : 'T =
#endif
match source with
| null -> fNull ()
| value -> value
Expand All @@ -30,7 +38,11 @@ module Obj =
/// <param name="source">The source object.</param>
/// <returns>The result of applying fValue to the source if it is not null; otherwise, the result of applying fNull.</returns>
/// <remarks>Only one of the functions is invoked based on the nullity of the source.</remarks>
#if NET9_0_OR_GREATER && !FABLE_COMPILER
let inline either ([<InlineIfLambda>]fValue: 'T -> 'U) ([<InlineIfLambda>]fNull: unit -> 'U) (source: 'T | null) : 'U =
#else
let inline either ([<InlineIfLambda>]fValue: 'T -> 'U) ([<InlineIfLambda>]fNull: unit -> 'U) (source: 'T) : 'U =
#endif
match source with
| null -> fNull ()
| value -> fValue value
3 changes: 2 additions & 1 deletion src/FSharpPlus/Internals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ module Errors =
let exnNoSubtraction = new System.Exception "No subtraction defined for these values in this domain."
let exnUnreachable = new System.InvalidOperationException "This execution path is unreachable."

// Functions to remove when compiling with F#9 or higher
#if !NET9_0_OR_GREATER || FABLE_COMPILER
let inline nullArgCheck paramName paramValue =
if isNull paramValue then nullArg paramName
else paramValue

module Unchecked = let nonNull = id
#endif

module Decimal =
let inline trySqrt x =
Expand Down
Loading