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

Merge main to release/dev17.12 #17450

Merged
merged 2 commits into from
Jul 29, 2024
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Core/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Added

* Enable C# collection expression support for F# lists & sets. ([Language suggestion #1355](https://github.com/fsharp/fslang-suggestions/issues/1355), [RFC FS-1145 (PR#776)](https://github.com/fsharp/fslang-design/pull/776), [PR #17359](https://github.com/dotnet/fsharp/pull/17359))
* Add module functions for converting between `'T option` and `'T voption`. ([PR #17436](https://github.com/dotnet/fsharp/pull/17436))

### Changed
* Change compiler default setting realsig+ when building assemblies ([Issue #17384](https://github.com/dotnet/fsharp/issues/17384), [PR #17378](https://github.com/dotnet/fsharp/pull/17385))
Expand Down
7 changes: 7 additions & 0 deletions docs/release-notes/.VisualStudio/17.12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Fixed

### Added

### Changed

### Breaking Changes
24 changes: 24 additions & 0 deletions src/FSharp.Core/option.fs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ module Option =
| Some x -> x
#endif

[<CompiledName("OfValueOption")>]
let inline ofValueOption (voption: 'T voption) =
match voption with
| ValueNone -> None
| ValueSome x -> Some x

[<CompiledName("ToValueOption")>]
let inline toValueOption (option: 'T option) =
match option with
| None -> ValueNone
| Some x -> ValueSome x

module ValueOption =

[<CompiledName("GetValue")>]
Expand Down Expand Up @@ -355,3 +367,15 @@ module ValueOption =
| ValueNone -> null
| ValueSome x -> x
#endif

[<CompiledName("OfOption")>]
let inline ofOption (option: 'T option) =
match option with
| None -> ValueNone
| Some x -> ValueSome x

[<CompiledName("ToOption")>]
let inline toOption (voption: 'T voption) =
match voption with
| ValueNone -> None
| ValueSome x -> Some x
60 changes: 60 additions & 0 deletions src/FSharp.Core/option.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,36 @@ module Option =
val inline toObj: value: 'T option -> 'T | null when 'T : not struct (* and 'T : not null *)
#endif

/// <summary>Convert a value option to an option.</summary>
///
/// <param name="voption">The input value option.</param>
///
/// <returns>The resulting option.</returns>
///
/// <example id="ofValueOption-1">
/// <code lang="fsharp">
/// ValueSome 42 |> Option.ofValueOption // evaluates to Some 42
/// (ValueNone: int voption) |> Option.ofValueOption // evaluates to None
/// </code>
/// </example>
[<CompiledName("OfValueOption")>]
val inline ofValueOption: voption: 'T voption -> 'T option

/// <summary>Convert an option to a value option.</summary>
///
/// <param name="option">The input option.</param>
///
/// <returns>The resulting value option.</returns>
///
/// <example id="toValueOption-1">
/// <code lang="fsharp">
/// Some 42 |> Option.toValueOption // evaluates to ValueSome 42
/// (None: int option) |> Option.toValueOption // evaluates to ValueNone
/// </code>
/// </example>
[<CompiledName("ToValueOption")>]
val inline toValueOption: option: 'T option -> 'T voption

/// <summary>Contains operations for working with value options.</summary>
///
/// <category>Options</category>
Expand Down Expand Up @@ -926,3 +956,33 @@ module ValueOption =
// TODO NULLNESS: assess this change - is it a breaking change?
val inline toObj: value: 'T voption -> 'T | null when 'T : not struct (* and 'T : not null *)
#endif

/// <summary>Convert an option to a value option.</summary>
///
/// <param name="option">The input option.</param>
///
/// <returns>The resulting value option.</returns>
///
/// <example id="ofOption-1">
/// <code lang="fsharp">
/// Some 42 |> ValueOption.ofOption // evaluates to ValueSome 42
/// (None: int option) |> ValueOption.ofOption // evaluates to ValueNone
/// </code>
/// </example>
[<CompiledName("OfOption")>]
val inline ofOption: option: 'T option -> 'T voption

/// <summary>Convert a value option to an option.</summary>
///
/// <param name="voption">The input value option.</param>
///
/// <returns>The resulting option.</returns>
///
/// <example id="toOption-1">
/// <code lang="fsharp">
/// ValueSome 42 |> ValueOption.toOption // evaluates to Some 42
/// (ValueNone: int voption) |> ValueOption.toOption // evaluates to None
/// </code>
/// </example>
[<CompiledName("ToOption")>]
val inline toOption: voption: 'T voption -> 'T option
Original file line number Diff line number Diff line change
Expand Up @@ -2016,8 +2016,10 @@ Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Filt
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Flatten[T](Microsoft.FSharp.Core.FSharpOption`1[Microsoft.FSharp.Core.FSharpOption`1[T]])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OfNullable[T](System.Nullable`1[T])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OfObj[T](T)
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OfValueOption[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OrElseWith[T](Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.FSharpOption`1[T]], Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OrElse[T](Microsoft.FSharp.Core.FSharpOption`1[T], Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpValueOption`1[T] ToValueOption[T](Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: T DefaultValue[T](T, Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: T DefaultWith[T](Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,T], Microsoft.FSharp.Core.FSharpOption`1[T])
Expand Down Expand Up @@ -2124,6 +2126,7 @@ Microsoft.FSharp.Core.ValueOption: Boolean IsNone[T](Microsoft.FSharp.Core.FShar
Microsoft.FSharp.Core.ValueOption: Boolean IsSome[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Int32 Count[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Collections.FSharpList`1[T] ToList[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpOption`1[T] ToOption[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] Bind[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Core.FSharpValueOption`1[T1], Microsoft.FSharp.Core.FSharpValueOption`1[T2])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] Map3[T1,T2,T3,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,Microsoft.FSharp.Core.FSharpFunc`2[T3,TResult]]], Microsoft.FSharp.Core.FSharpValueOption`1[T1], Microsoft.FSharp.Core.FSharpValueOption`1[T2], Microsoft.FSharp.Core.FSharpValueOption`1[T3])
Expand All @@ -2132,6 +2135,7 @@ Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T]
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] Flatten[T](Microsoft.FSharp.Core.FSharpValueOption`1[Microsoft.FSharp.Core.FSharpValueOption`1[T]])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OfNullable[T](System.Nullable`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OfObj[T](T)
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OfOption[T](Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OrElseWith[T](Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.FSharpValueOption`1[T]], Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OrElse[T](Microsoft.FSharp.Core.FSharpValueOption`1[T], Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2019,8 +2019,10 @@ Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Filt
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Flatten[T](Microsoft.FSharp.Core.FSharpOption`1[Microsoft.FSharp.Core.FSharpOption`1[T]])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OfNullable[T](System.Nullable`1[T])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OfObj[T](T)
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OfValueOption[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OrElseWith[T](Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.FSharpOption`1[T]], Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] OrElse[T](Microsoft.FSharp.Core.FSharpOption`1[T], Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpValueOption`1[T] ToValueOption[T](Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: T DefaultValue[T](T, Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.OptionModule: T DefaultWith[T](Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,T], Microsoft.FSharp.Core.FSharpOption`1[T])
Expand Down Expand Up @@ -2127,6 +2129,7 @@ Microsoft.FSharp.Core.ValueOption: Boolean IsNone[T](Microsoft.FSharp.Core.FShar
Microsoft.FSharp.Core.ValueOption: Boolean IsSome[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Int32 Count[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Collections.FSharpList`1[T] ToList[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpOption`1[T] ToOption[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] Bind[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpValueOption`1[TResult]], Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Core.FSharpValueOption`1[T1], Microsoft.FSharp.Core.FSharpValueOption`1[T2])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[TResult] Map3[T1,T2,T3,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,Microsoft.FSharp.Core.FSharpFunc`2[T3,TResult]]], Microsoft.FSharp.Core.FSharpValueOption`1[T1], Microsoft.FSharp.Core.FSharpValueOption`1[T2], Microsoft.FSharp.Core.FSharpValueOption`1[T3])
Expand All @@ -2135,6 +2138,7 @@ Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T]
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] Flatten[T](Microsoft.FSharp.Core.FSharpValueOption`1[Microsoft.FSharp.Core.FSharpValueOption`1[T]])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OfNullable[T](System.Nullable`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OfObj[T](T)
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OfOption[T](Microsoft.FSharp.Core.FSharpOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OrElseWith[T](Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.FSharpValueOption`1[T]], Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: Microsoft.FSharp.Core.FSharpValueOption`1[T] OrElse[T](Microsoft.FSharp.Core.FSharpValueOption`1[T], Microsoft.FSharp.Core.FSharpValueOption`1[T])
Microsoft.FSharp.Core.ValueOption: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpValueOption`1[T])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ type OptionModule() =
Assert.True( Option.ofObj<string[]> null = None)
Assert.True( Option.ofObj<int[]> null = None)

[<Fact>]
member this.OfToValueOption() =
Assert.Equal(ValueSome 3, Option.toValueOption (Some 3))
Assert.Equal(ValueNone, Option.toValueOption (None: int option))
Assert.Equal(Some 3, Option.ofValueOption (ValueSome 3))
Assert.Equal(None, Option.ofValueOption (ValueNone: int voption))

[<Fact>]
member this.DefaultValue() =
Assert.AreEqual( Option.defaultValue 3 None, 3)
Expand Down Expand Up @@ -380,6 +387,13 @@ type ValueOptionTests() =
Assert.True(ValueOption.ofObj<string[]> null = ValueNone)
Assert.True(ValueOption.ofObj<int[]> null = ValueNone)

[<Fact>]
member this.OfToOption() =
Assert.Equal(Some 3, ValueOption.toOption (ValueSome 3))
Assert.Equal(None, ValueOption.toOption (ValueNone: int voption))
Assert.Equal(ValueSome 3, ValueOption.ofOption (Some 3))
Assert.Equal(ValueNone, ValueOption.ofOption (None: int option))

[<Fact>]
member this.DefaultValue() =
Assert.AreEqual(ValueOption.defaultValue 3 ValueNone, 3)
Expand Down
Loading