diff --git a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Core/OptionModule.fs b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Core/OptionModule.fs index b2010567f13..595eb7457cc 100644 --- a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Core/OptionModule.fs +++ b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Core/OptionModule.fs @@ -18,6 +18,15 @@ Make sure each method works on: [] type OptionModule() = + let assertWasNotCalledThunk () = raise (exn "Thunk should not have been called.") + + [] + member this.Flatten () = + Assert.AreEqual( Option.flatten None, None) + Assert.AreEqual( Option.flatten (Some None), None) + Assert.AreEqual( Option.flatten (Some <| Some 1), Some 1) + Assert.AreEqual( Option.flatten (Some <| Some ""), Some "") + [] member this.FilterSomeIntegerWhenPredicateReturnsTrue () = let test x = @@ -98,7 +107,17 @@ type OptionModule() = let expected = None Assert.AreEqual(expected, actual) [""; " "; "Baz Quux"; "Corge grault"] |> List.iter test - + + [] + member this.Contains() = + Assert.IsFalse( Option.contains 1 None) + Assert.IsTrue( Option.contains 1 (Some 1)) + + Assert.IsFalse( Option.contains "" None) + Assert.IsTrue( Option.contains "" (Some "")) + + Assert.IsFalse( Option.contains None None) + Assert.IsTrue( Option.contains None (Some None)) [] member this.OfToNullable() = Assert.IsTrue( Option.ofNullable (System.Nullable()) = None) @@ -121,4 +140,79 @@ type OptionModule() = Assert.IsTrue( Option.ofObj (null : string array) = None) Assert.IsTrue( Option.ofObj null = None) Assert.IsTrue( Option.ofObj null = None) - Assert.IsTrue( Option.ofObj null = None) \ No newline at end of file + Assert.IsTrue( Option.ofObj null = None) + + [] + member this.DefaultValue() = + Assert.AreEqual( Option.defaultValue 3 None, 3) + Assert.AreEqual( Option.defaultValue 3 (Some 42), 42) + Assert.AreEqual( Option.defaultValue "" None, "") + Assert.AreEqual( Option.defaultValue "" (Some "x"), "x") + + [] + member this.DefaultWith() = + Assert.AreEqual( Option.defaultWith (fun () -> 3) None, 3) + Assert.AreEqual( Option.defaultWith (fun () -> "") None, "") + + Assert.AreEqual( Option.defaultWith assertWasNotCalledThunk (Some 42), 42) + Assert.AreEqual( Option.defaultWith assertWasNotCalledThunk (Some ""), "") + + [] + member this.OrElse() = + Assert.AreEqual( Option.orElse None None, None) + Assert.AreEqual( Option.orElse (Some 3) None, Some 3) + Assert.AreEqual( Option.orElse None (Some 42), Some 42) + Assert.AreEqual( Option.orElse (Some 3) (Some 42), Some 42) + + Assert.AreEqual( Option.orElse (Some "") None, Some "") + Assert.AreEqual( Option.orElse None (Some "x"), Some "x") + Assert.AreEqual( Option.orElse (Some "") (Some "x"), Some "x") + + [] + member this.OrElseWith() = + Assert.AreEqual( Option.orElseWith (fun () -> None) None, None) + Assert.AreEqual( Option.orElseWith (fun () -> Some 3) None, Some 3) + Assert.AreEqual( Option.orElseWith (fun () -> Some "") None, Some "") + + Assert.AreEqual( Option.orElseWith assertWasNotCalledThunk (Some 42), Some 42) + Assert.AreEqual( Option.orElseWith assertWasNotCalledThunk (Some ""), Some "") + + [] + member this.Map2() = + Assert.AreEqual( Option.map2 (-) None None, None) + Assert.AreEqual( Option.map2 (-) (Some 1) None, None) + Assert.AreEqual( Option.map2 (-) None (Some 2), None) + Assert.AreEqual( Option.map2 (-) (Some 1) (Some 2), Some -1) + + Assert.AreEqual( Option.map2 (+) None None, None) + Assert.AreEqual( Option.map2 (+) (Some "x") None, None) + Assert.AreEqual( Option.map2 (+) None (Some "y"), None) + Assert.AreEqual( Option.map2 (+) (Some "x") (Some "y"), Some "xy") + + [] + member this.Map3() = + let add3 x y z = string x + string y + string z + Assert.AreEqual( Option.map3 add3 None None None, None) + Assert.AreEqual( Option.map3 add3 (Some 1) None None, None) + Assert.AreEqual( Option.map3 add3 None (Some 2) None, None) + Assert.AreEqual( Option.map3 add3 (Some 1) (Some 2) None, None) + Assert.AreEqual( Option.map3 add3 None None (Some 3), None) + Assert.AreEqual( Option.map3 add3 (Some 1) None (Some 3), None) + Assert.AreEqual( Option.map3 add3 None (Some 2) (Some 3), None) + Assert.AreEqual( Option.map3 add3 (Some 1) (Some 2) (Some 3), Some "123") + + let concat3 x y z = x + y + z + Assert.AreEqual( Option.map3 concat3 None None None, None) + Assert.AreEqual( Option.map3 concat3 (Some "x") None None, None) + Assert.AreEqual( Option.map3 concat3 None (Some "y") None, None) + Assert.AreEqual( Option.map3 concat3 (Some "x") (Some "y") None, None) + Assert.AreEqual( Option.map3 concat3 None None (Some "z"), None) + Assert.AreEqual( Option.map3 concat3 (Some "x") None (Some "z"), None) + Assert.AreEqual( Option.map3 concat3 None (Some "y") (Some "z"), None) + Assert.AreEqual( Option.map3 concat3 (Some "x") (Some "y") (Some "z"), Some "xyz") + + [] + member this.MapBindEquivalenceProperties () = + let fn x = x + 3 + Assert.AreEqual(Option.map fn None, Option.bind (fn >> Some) None) + Assert.AreEqual(Option.map fn (Some 5), Option.bind (fn >> Some) (Some 5)) \ No newline at end of file diff --git a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.coreclr.fs b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.coreclr.fs index 10c4389cb95..f2f634cab1f 100644 --- a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.coreclr.fs +++ b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.coreclr.fs @@ -2713,6 +2713,7 @@ Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures+FSharpFunc`6[T1,T2,T3,T4,T5,TResult] Microsoft.FSharp.Core.OptimizedClosures: System.String ToString() Microsoft.FSharp.Core.OptimizedClosures: System.Type GetType() +Microsoft.FSharp.Core.OptionModule: Boolean Contains[T](T, Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean Equals(System.Object) Microsoft.FSharp.Core.OptionModule: Boolean Exists[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean ForAll[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) @@ -2722,13 +2723,20 @@ Microsoft.FSharp.Core.OptionModule: Int32 Count[T](Microsoft.FSharp.Core.FSharpO Microsoft.FSharp.Core.OptionModule: Int32 GetHashCode() Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Collections.FSharpList`1[T] ToList[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Bind[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Core.FSharpOption`1[T]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Core.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`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.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2], Microsoft.FSharp.Core.FSharpOption`1[T3]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) +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] 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: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: System.String ToString() Microsoft.FSharp.Core.OptionModule: System.Type GetType() +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]) Microsoft.FSharp.Core.OptionModule: T GetValue[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: T ToObj[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: TState FoldBack[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]], Microsoft.FSharp.Core.FSharpOption`1[T], TState) diff --git a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.net40.fs b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.net40.fs index c452c3f31c4..99d38a69f95 100644 --- a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.net40.fs +++ b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.net40.fs @@ -2747,6 +2747,7 @@ Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures+FSharpFunc`6[T1,T2,T3,T4,T5,TResult] Microsoft.FSharp.Core.OptimizedClosures: System.String ToString() Microsoft.FSharp.Core.OptimizedClosures: System.Type GetType() +Microsoft.FSharp.Core.OptionModule: Boolean Contains[T](T, Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean Equals(System.Object) Microsoft.FSharp.Core.OptionModule: Boolean Exists[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean ForAll[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) @@ -2756,13 +2757,20 @@ Microsoft.FSharp.Core.OptionModule: Int32 Count[T](Microsoft.FSharp.Core.FSharpO Microsoft.FSharp.Core.OptionModule: Int32 GetHashCode() Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Collections.FSharpList`1[T] ToList[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Bind[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Core.FSharpOption`1[T]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Core.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`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.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2], Microsoft.FSharp.Core.FSharpOption`1[T3]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) +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] 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: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: System.String ToString() Microsoft.FSharp.Core.OptionModule: System.Type GetType() +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]) Microsoft.FSharp.Core.OptionModule: T GetValue[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: T ToObj[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: TState FoldBack[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]], Microsoft.FSharp.Core.FSharpOption`1[T], TState) diff --git a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable259.fs b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable259.fs index 8e5337ef4a8..d799117f863 100644 --- a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable259.fs +++ b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable259.fs @@ -2718,6 +2718,7 @@ Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures+FSharpFunc`6[T1,T2,T3,T4,T5,TResult] Microsoft.FSharp.Core.OptimizedClosures: System.String ToString() Microsoft.FSharp.Core.OptimizedClosures: System.Type GetType() +Microsoft.FSharp.Core.OptionModule: Boolean Contains[T](T, Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean Equals(System.Object) Microsoft.FSharp.Core.OptionModule: Boolean Exists[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean ForAll[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) @@ -2727,13 +2728,20 @@ Microsoft.FSharp.Core.OptionModule: Int32 Count[T](Microsoft.FSharp.Core.FSharpO Microsoft.FSharp.Core.OptionModule: Int32 GetHashCode() Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Collections.FSharpList`1[T] ToList[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Bind[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Core.FSharpOption`1[T]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Core.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`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.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2], Microsoft.FSharp.Core.FSharpOption`1[T3]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) +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] 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: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: System.String ToString() Microsoft.FSharp.Core.OptionModule: System.Type GetType() +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]) Microsoft.FSharp.Core.OptionModule: T GetValue[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: T ToObj[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: TState FoldBack[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]], Microsoft.FSharp.Core.FSharpOption`1[T], TState) diff --git a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable47.fs b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable47.fs index 531eebf0e8f..9c0f389633d 100644 --- a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable47.fs +++ b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable47.fs @@ -2719,6 +2719,7 @@ Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures+FSharpFunc`6[T1,T2,T3,T4,T5,TResult] Microsoft.FSharp.Core.OptimizedClosures: System.String ToString() Microsoft.FSharp.Core.OptimizedClosures: System.Type GetType() +Microsoft.FSharp.Core.OptionModule: Boolean Contains[T](T, Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean Equals(System.Object) Microsoft.FSharp.Core.OptionModule: Boolean Exists[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean ForAll[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) @@ -2728,13 +2729,20 @@ Microsoft.FSharp.Core.OptionModule: Int32 Count[T](Microsoft.FSharp.Core.FSharpO Microsoft.FSharp.Core.OptionModule: Int32 GetHashCode() Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Collections.FSharpList`1[T] ToList[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Bind[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Core.FSharpOption`1[T]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Core.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`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.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2], Microsoft.FSharp.Core.FSharpOption`1[T3]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) +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] 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: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: System.String ToString() Microsoft.FSharp.Core.OptionModule: System.Type GetType() +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]) Microsoft.FSharp.Core.OptionModule: T GetValue[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: T ToObj[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: TState FoldBack[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]], Microsoft.FSharp.Core.FSharpOption`1[T], TState) diff --git a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable7.fs b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable7.fs index 7d320ad8483..b9de41ca1eb 100644 --- a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable7.fs +++ b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable7.fs @@ -2731,6 +2731,7 @@ Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures+FSharpFunc`6[T1,T2,T3,T4,T5,TResult] Microsoft.FSharp.Core.OptimizedClosures: System.String ToString() Microsoft.FSharp.Core.OptimizedClosures: System.Type GetType() +Microsoft.FSharp.Core.OptionModule: Boolean Contains[T](T, Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean Equals(System.Object) Microsoft.FSharp.Core.OptionModule: Boolean Exists[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean ForAll[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) @@ -2740,13 +2741,20 @@ Microsoft.FSharp.Core.OptionModule: Int32 Count[T](Microsoft.FSharp.Core.FSharpO Microsoft.FSharp.Core.OptionModule: Int32 GetHashCode() Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Collections.FSharpList`1[T] ToList[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Bind[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Core.FSharpOption`1[T]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Core.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`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.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2], Microsoft.FSharp.Core.FSharpOption`1[T3]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) +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] 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: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: System.String ToString() Microsoft.FSharp.Core.OptionModule: System.Type GetType() +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]) Microsoft.FSharp.Core.OptionModule: T GetValue[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: T ToObj[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: TState FoldBack[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]], Microsoft.FSharp.Core.FSharpOption`1[T], TState) diff --git a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable78.fs b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable78.fs index f731fcdbcc0..aedaca4bff3 100644 --- a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable78.fs +++ b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable78.fs @@ -2718,6 +2718,7 @@ Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures Microsoft.FSharp.Core.OptimizedClosures: Microsoft.FSharp.Core.OptimizedClosures+FSharpFunc`6[T1,T2,T3,T4,T5,TResult] Microsoft.FSharp.Core.OptimizedClosures: System.String ToString() Microsoft.FSharp.Core.OptimizedClosures: System.Type GetType() +Microsoft.FSharp.Core.OptionModule: Boolean Contains[T](T, Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean Equals(System.Object) Microsoft.FSharp.Core.OptionModule: Boolean Exists[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Boolean ForAll[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) @@ -2727,13 +2728,20 @@ Microsoft.FSharp.Core.OptionModule: Int32 Count[T](Microsoft.FSharp.Core.FSharpO Microsoft.FSharp.Core.OptionModule: Int32 GetHashCode() Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Collections.FSharpList`1[T] ToList[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Bind[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpOption`1[TResult]], Microsoft.FSharp.Core.FSharpOption`1[T]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map2[T1,T2,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T1,Microsoft.FSharp.Core.FSharpFunc`2[T2,TResult]], Microsoft.FSharp.Core.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2]) +Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`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.FSharpOption`1[T1], Microsoft.FSharp.Core.FSharpOption`1[T2], Microsoft.FSharp.Core.FSharpOption`1[T3]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: Microsoft.FSharp.Core.FSharpOption`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Core.FSharpOption`1[T]) +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] 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: System.Nullable`1[T] ToNullable[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: System.String ToString() Microsoft.FSharp.Core.OptionModule: System.Type GetType() +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]) Microsoft.FSharp.Core.OptionModule: T GetValue[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: T ToObj[T](Microsoft.FSharp.Core.FSharpOption`1[T]) Microsoft.FSharp.Core.OptionModule: TState FoldBack[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]], Microsoft.FSharp.Core.FSharpOption`1[T], TState) diff --git a/src/fsharp/FSharp.Core/option.fs b/src/fsharp/FSharp.Core/option.fs index 3bca435ce6b..17a5c41591b 100644 --- a/src/fsharp/FSharp.Core/option.fs +++ b/src/fsharp/FSharp.Core/option.fs @@ -16,6 +16,18 @@ namespace Microsoft.FSharp.Core [] let inline isNone option = match option with None -> true | Some _ -> false + [] + let defaultValue def option = match option with None -> def | Some v -> v + + [] + let defaultWith defThunk option = match option with None -> defThunk () | Some v -> v + + [] + let orElse ifNone option = match option with None -> ifNone | Some _ -> option + + [] + let orElseWith ifNoneThunk option = match option with None -> ifNoneThunk () | Some _ -> option + [] let count option = match option with None -> 0 | Some _ -> 1 @@ -31,15 +43,33 @@ namespace Microsoft.FSharp.Core [] let forall p inp = match inp with None -> true | Some x -> p x + [] + let inline contains x inp = match inp with None -> false | Some v -> v = x + [] let iter f inp = match inp with None -> () | Some x -> f x [] let map f inp = match inp with None -> None | Some x -> Some (f x) + [] + let map2 f option1 option2 = + match option1, option2 with + | Some x, Some y -> Some <| f x y + | _ -> None + + [] + let map3 f option1 option2 option3 = + match option1, option2, option3 with + | Some x, Some y, Some z -> Some <| f x y z + | _ -> None + [] let bind f inp = match inp with None -> None | Some x -> f x + [] + let flatten option = match option with None -> None | Some x -> x + [] let filter f inp = match inp with None -> None | Some x -> if f x then Some x else None diff --git a/src/fsharp/FSharp.Core/option.fsi b/src/fsharp/FSharp.Core/option.fsi index 3225893e284..7296d739366 100644 --- a/src/fsharp/FSharp.Core/option.fsi +++ b/src/fsharp/FSharp.Core/option.fsi @@ -23,6 +23,37 @@ namespace Microsoft.FSharp.Core [] val inline isNone: option:'T option -> bool + /// Gets the value of the option if the option is Some, otherwise returns the specified default value. + /// The specified default value. + /// The input option. + /// The option if the option is Some, else the default value. + /// Identical to the built-in operator, except with the arguments swapped. + [] + val defaultValue: value:'T -> option:'T option -> 'T + + /// Gets the value of the option if the option is Some, otherwise evaluates and returns the result. + /// A thunk that provides a default value when evaluated. + /// The input option. + /// The option if the option is Some, else the result of evaluating . + /// is not evaluated unless is None. + [] + val defaultWith: defThunk:(unit -> 'T) -> option:'T option -> 'T + + /// Returns if it is Some, otherwise returns . + /// The value to use if is None. + /// The input option. + /// The option if the option is Some, else the alternate option. + [] + val orElse: ifNone:'T option -> option:'T option -> 'T option + + /// Returns if it is Some, otherwise evaluates and returns the result. + /// A thunk that provides an alternate option when evaluated. + /// The input option. + /// The option if the option is Some, else the result of evaluating . + /// is not evaluated unless is None. + [] + val orElseWith: ifNoneThunk:(unit -> 'T option) -> option:'T option -> 'T option + /// Gets the value associated with the option. /// The input option. /// The value within the option. @@ -70,6 +101,13 @@ namespace Microsoft.FSharp.Core [] val forall: predicate:('T -> bool) -> option:'T option -> bool + /// Evaluates to true if is Some and its value is equal to . + /// The value to test for equality. + /// The input option. + /// True if the option is Some and contains a value equal to , otherwise false. + [] + val inline contains: value:'T -> option:'T option -> bool when 'T : equality + /// iter f inp executes match inp with None -> () | Some x -> f x. /// A function to apply to the option value. /// The input option. @@ -85,6 +123,23 @@ namespace Microsoft.FSharp.Core [] val map: mapping:('T -> 'U) -> option:'T option -> 'U option + /// map f option1 option2 evaluates to match option1, option2 with Some x, Some y -> Some (f x y) | _ -> None. + /// A function to apply to the option values. + /// The first option. + /// The second option. + /// An option of the input values after applying the mapping function, or None if either input is None. + [] + val map2: mapping:('T1 -> 'T2 -> 'U) -> 'T1 option -> 'T2 option -> 'U option + + /// map f option1 option2 option3 evaluates to match option1, option2, option3 with Some x, Some y, Some z -> Some (f x y z) | _ -> None. + /// A function to apply to the option values. + /// The first option. + /// The second option. + /// The third option. + /// An option of the input values after applying the mapping function, or None if any input is None. + [] + val map3: mapping:('T1 -> 'T2 -> 'T3 -> 'U) -> 'T1 option -> 'T2 option -> 'T3 option -> 'U option + /// bind f inp evaluates to match inp with None -> None | Some x -> f x /// A function that takes the value of type T from an option and transforms it into /// an option containing a value of type U. @@ -93,6 +148,13 @@ namespace Microsoft.FSharp.Core [] val bind: binder:('T -> 'U option) -> option:'T option -> 'U option + /// flatten inp evaluates to match inp with None -> None | Some x -> x + /// The input option. + /// An option of the output type of the binder. + /// flatten is equivalent to bind id. + [] + val flatten: option:'T option option -> 'T option + /// filter f inp evaluates to match inp with None -> None | Some x -> if f x then Some x else None. /// A function that evaluates whether the value contained in the option should remain, or be filtered out. /// The input option. diff --git a/tests/fsharpqa/testenv/bin/System.ValueTuple.dll b/tests/fsharpqa/testenv/bin/System.ValueTuple.dll new file mode 100644 index 00000000000..9b6bbf8db5f Binary files /dev/null and b/tests/fsharpqa/testenv/bin/System.ValueTuple.dll differ