From c006ee6b65bbc95f1fc3b36ac37cdf4b7c5ad1f3 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Sat, 6 Apr 2024 12:00:36 -0400 Subject: [PATCH] 209 remove MergeSources (and!) from some implementations (#261) * Remove MergeSources from resultCE * Remove MergeSources from AsyncResult * Remove MergeSources from ResultOption * Fixup resultOption docs * Remove MergeSources from OptionCE * Remove MergeSources from ValueOptionCE * remove MergeSources Option/ValueOption --- benchmarks/ApplicativeTests.fs | 55 ----- gitbook/resultOption/ce.md | 4 +- src/FsToolkit.ErrorHandling/AsyncResultCE.fs | 8 - src/FsToolkit.ErrorHandling/OptionCE.fs | 30 --- src/FsToolkit.ErrorHandling/ResultCE.fs | 7 - src/FsToolkit.ErrorHandling/ResultOptionCE.fs | 7 - src/FsToolkit.ErrorHandling/ValueOptionCE.fs | 13 -- .../AsyncResultCE.fs | 168 ------------- .../FsToolkit.ErrorHandling.Tests/OptionCE.fs | 220 ----------------- .../FsToolkit.ErrorHandling.Tests/ResultCE.fs | 97 -------- .../ResultOptionCE.fs | 97 -------- .../ValueOptionCE.fs | 221 ------------------ 12 files changed, 2 insertions(+), 925 deletions(-) diff --git a/benchmarks/ApplicativeTests.fs b/benchmarks/ApplicativeTests.fs index 667dde0e..3b417a18 100644 --- a/benchmarks/ApplicativeTests.fs +++ b/benchmarks/ApplicativeTests.fs @@ -41,19 +41,6 @@ type Result_BindvsAndCEBenchmarks() = } |> ignore - [] - member this.All_Success_And() = - result { - let! r1 = successSlowSync this.delay - and! r2 = successSlowSync this.delay - and! r3 = successSlowSync this.delay - - return - r1 - + r2 - + r3 - } - |> ignore [] member this.Fail_First_Bind() = @@ -69,20 +56,6 @@ type Result_BindvsAndCEBenchmarks() = } |> ignore - [] - member this.Fail_First_And() = - result { - let! r1 = errorSlowSync this.delay - and! r2 = successSlowSync this.delay - and! r3 = successSlowSync this.delay - - return - r1 - + r2 - + r3 - } - |> ignore - [] member this.Fail_Mid_Bind() = result { @@ -97,20 +70,6 @@ type Result_BindvsAndCEBenchmarks() = } |> ignore - [] - member this.Fail_Mid_And() = - result { - let! r1 = successSlowSync this.delay - and! r2 = errorSlowSync this.delay - and! r3 = successSlowSync this.delay - - return - r1 - + r2 - + r3 - } - |> ignore - [] member this.Fail_Last_Bind() = result { @@ -124,17 +83,3 @@ type Result_BindvsAndCEBenchmarks() = + r3 } |> ignore - - [] - member this.Fail_Last_And() = - result { - let! r1 = successSlowSync this.delay - and! r2 = successSlowSync this.delay - and! r3 = errorSlowSync this.delay - - return - r1 - + r2 - + r3 - } - |> ignore diff --git a/gitbook/resultOption/ce.md b/gitbook/resultOption/ce.md index 8ccc5c84..2cd82b7e 100644 --- a/gitbook/resultOption/ce.md +++ b/gitbook/resultOption/ce.md @@ -25,8 +25,8 @@ let add x y z = x + y + z let addResult : Result = resultOption { let! x = Ok (Some 30) - and! y = Error "Oops 1" - and! z = Error "Oops 2" + let! y = Error "Oops 1" + let! z = Error "Oops 2" return add x y z } // Error "Oops 1" diff --git a/src/FsToolkit.ErrorHandling/AsyncResultCE.fs b/src/FsToolkit.ErrorHandling/AsyncResultCE.fs index a4cdd044..6116b3da 100644 --- a/src/FsToolkit.ErrorHandling/AsyncResultCE.fs +++ b/src/FsToolkit.ErrorHandling/AsyncResultCE.fs @@ -112,14 +112,6 @@ module AsyncResultCE = ) : Async> = AsyncResult.map f x - member inline _.MergeSources - ( - t1: Async>, - t2: Async> - ) : Async> = - AsyncResult.zip t1 t2 - - /// /// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type. /// diff --git a/src/FsToolkit.ErrorHandling/OptionCE.fs b/src/FsToolkit.ErrorHandling/OptionCE.fs index 5c643aba..85423c87 100644 --- a/src/FsToolkit.ErrorHandling/OptionCE.fs +++ b/src/FsToolkit.ErrorHandling/OptionCE.fs @@ -111,13 +111,6 @@ module OptionCE = ) : 'output option = Option.map f (Option.ofObj x) - member inline _.MergeSources - ( - option1: 'left option, - option2: 'right option - ) : ('left * 'right) option = - Option.zip option1 option2 - /// /// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type. /// @@ -145,29 +138,6 @@ module OptionExtensionsLower = member inline _.Source(m: string) : string option = Option.ofObj m - member inline _.MergeSources - ( - nullableObj1: 'left, - option2: 'right option - ) : ('left * 'right) option = - Option.zip (Option.ofObj nullableObj1) option2 - - - member inline _.MergeSources - ( - option1: 'left option, - nullableObj2: 'right - ) : ('left * 'right) option = - Option.zip (option1) (Option.ofObj nullableObj2) - - - member inline _.MergeSources - ( - nullableObj1: 'left, - nullableObj2: 'right - ) : ('left * 'right) option = - Option.zip (Option.ofObj nullableObj1) (Option.ofObj nullableObj2) - [] module OptionExtensions = open System diff --git a/src/FsToolkit.ErrorHandling/ResultCE.fs b/src/FsToolkit.ErrorHandling/ResultCE.fs index 9ef5afb6..e1b43386 100644 --- a/src/FsToolkit.ErrorHandling/ResultCE.fs +++ b/src/FsToolkit.ErrorHandling/ResultCE.fs @@ -109,13 +109,6 @@ module ResultCE = ) : Result<'okOutput, 'error> = Result.map f x - member inline _.MergeSources - ( - left: Result<'left, 'error>, - right: Result<'right, 'error> - ) : Result<'left * 'right, 'error> = - Result.zip left right - /// /// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type. /// diff --git a/src/FsToolkit.ErrorHandling/ResultOptionCE.fs b/src/FsToolkit.ErrorHandling/ResultOptionCE.fs index 60913fc1..60b9db0f 100644 --- a/src/FsToolkit.ErrorHandling/ResultOptionCE.fs +++ b/src/FsToolkit.ErrorHandling/ResultOptionCE.fs @@ -114,13 +114,6 @@ module ResultOptionCE = ) : Result<'U option, 'TError> = ResultOption.map binder resultOpt - member inline _.MergeSources - ( - left: Result<'left option, 'error>, - right: Result<'right option, 'error> - ) : Result<('left * 'right) option, 'error> = - ResultOption.zip left right - member inline _.Source(result: Result<'ok option, 'error>) : Result<'ok option, 'error> = result diff --git a/src/FsToolkit.ErrorHandling/ValueOptionCE.fs b/src/FsToolkit.ErrorHandling/ValueOptionCE.fs index 67893f16..9b570098 100644 --- a/src/FsToolkit.ErrorHandling/ValueOptionCE.fs +++ b/src/FsToolkit.ErrorHandling/ValueOptionCE.fs @@ -103,8 +103,6 @@ module ValueOptionCE = |> ValueOption.ofObj |> ValueOption.map f - member inline _.MergeSources(option1, option2) = ValueOption.zip option1 option2 - /// /// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type. /// @@ -127,17 +125,6 @@ module ValueOptionExtensionsLower = m |> ValueOption.ofObj - member inline _.MergeSources(nullableObj1, option2) = - ValueOption.zip (ValueOption.ofObj nullableObj1) option2 - - - member inline _.MergeSources(option1, nullableObj2) = - ValueOption.zip (option1) (ValueOption.ofObj nullableObj2) - - - member inline _.MergeSources(nullableObj1, nullableObj2) = - ValueOption.zip (ValueOption.ofObj nullableObj1) (ValueOption.ofObj nullableObj2) - [] module ValueOptionExtensions = open System diff --git a/tests/FsToolkit.ErrorHandling.Tests/AsyncResultCE.fs b/tests/FsToolkit.ErrorHandling.Tests/AsyncResultCE.fs index 93a9f0ca..e2ba9d0d 100644 --- a/tests/FsToolkit.ErrorHandling.Tests/AsyncResultCE.fs +++ b/tests/FsToolkit.ErrorHandling.Tests/AsyncResultCE.fs @@ -526,173 +526,6 @@ let toTaskResult v = |> Task.FromResult #endif -let ``AsyncResultCE applicative tests`` = - testList "AsyncResultCE applicative tests" [ - testCaseAsync "Happy Path AsyncResult" - <| async { - let! actual = - asyncResult { - let! a = AsyncResult.retn 3 - and! b = AsyncResult.retn 2 - and! c = AsyncResult.retn 1 - return a + b - c - } - - Expect.equal actual (Ok 4) "Should be ok" - } - -#if !FABLE_COMPILER - - testCaseAsync "Happy Path TaskResult" - <| async { - let! actual = - asyncResult { - let! a = toTaskResult 3 - and! b = toTaskResult 2 - and! c = toTaskResult 1 - return a + b - c - } - - Expect.equal actual (Ok 4) "Should be ok" - } - -#endif - - testCaseAsync "Happy Path Result" - <| async { - let! actual = - asyncResult { - let! a = Result.Ok 3 - and! b = Result.Ok 2 - and! c = Result.Ok 1 - return a + b - c - } - - Expect.equal actual (Ok 4) "Should be ok" - } - - testCaseAsync "Happy Path Choice" - <| async { - let! actual = - asyncResult { - let! a = Choice1Of2 3 - and! b = Choice1Of2 2 - and! c = Choice1Of2 1 - return a + b - c - } - - Expect.equal actual (Ok 4) "Should be ok" - } - - // Cannot get this to compile properly - testCaseAsync "Happy Path Async" - <| async { - let! actual = - asyncResult { - let! a = Async.singleton 3 //: Async - and! b = Async.singleton 2 //: Async - and! c = Async.singleton 1 //: Async - return a + b - c - } - - Expect.equal actual (Ok 4) "Should be ok" - } - - testCaseAsync "Happy Path 2 Async" - <| async { - let! actual = - asyncResult { - let! a = Async.singleton 3 //: Async - and! b = Async.singleton 2 //: Async - return a + b - } - - Expect.equal actual (Ok 5) "Should be ok" - } - -#if !FABLE_COMPILER - - testCaseAsync "Happy Path 2 Task" - <| async { - let! actual = - asyncResult { - let! a = Task.FromResult 3 - and! b = Task.FromResult 2 - return a + b - } - - Expect.equal actual (Ok 5) "Should be ok" - } - -#endif - - testCaseAsync "Happy Path Result/Choice/AsyncResult" - <| async { - let! actual = - asyncResult { - let! a = Ok 3 - and! b = Choice1Of2 2 - - and! c = - Ok 1 - |> Async.singleton - - return a + b - c - } - - Expect.equal actual (Ok 4) "Should be ok" - } - - testCaseAsync "Fail Path Result" - <| async { - let expected = Error "TryParse failure" - - let! actual = - asyncResult { - let! a = Ok 3 - and! b = Ok 2 - and! c = expected - return a + b - c - } - - Expect.equal actual expected "Should be Error" - } - - testCaseAsync "Fail Path Choice" - <| async { - let errorMsg = "TryParse failure" - - let! actual = - asyncResult { - let! a = Choice1Of2 3 - and! b = Choice1Of2 2 - and! c = Choice2Of2 errorMsg - return a + b - c - } - - Expect.equal actual (Error errorMsg) "Should be Error" - } - - testCaseAsync "Fail Path Result/Choice/AsyncResult" - <| async { - let errorMsg = "TryParse failure" - - let! actual = - asyncResult { - let! a = Choice1Of2 3 - - and! b = - Ok 2 - |> Async.singleton - - and! c = Error errorMsg - return a + b - c - } - - Expect.equal actual (Error errorMsg) "Should be Error" - } - ] - let ``AsyncResultCE Stack Trace Tests`` = @@ -769,7 +602,6 @@ let allTests = ``AsyncResultCE try Tests`` ``AsyncResultCE using Tests`` ``AsyncResultCE loop Tests`` - ``AsyncResultCE applicative tests`` ``AsyncResultCE Stack Trace Tests`` ``AsyncResultCE inference checks`` ] diff --git a/tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs b/tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs index 9eaca488..4dac455a 100644 --- a/tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs +++ b/tests/FsToolkit.ErrorHandling.Tests/OptionCE.fs @@ -319,225 +319,6 @@ type CustomClass(x: int) = member _.getX = x -let ``OptionCE applicative tests`` = - testList "OptionCE applicative tests" [ - testCase "Happy Path Option.Some" - <| fun () -> - let actual = - option { - let! a = Some 3 - and! b = Some 2 - and! c = Some 1 - return a + b - c - } - - Expect.equal actual (Some 4) "Should be Some 4" - - testCase "Happy Path Nullable" - <| fun () -> - let actual = - option { - let! a = Nullable<_> 3 - and! b = Nullable<_> 2 - and! c = Nullable<_> 1 - return a + b - c - } - - Expect.equal actual (Some 4) "Should be Some 4" - - testCase "Happy Path null Objects" - <| fun () -> - // let hello = CustomClass - let actual = - option { - let! a = CustomClass 3 - and! b = CustomClass 2 - and! c = CustomClass 1 - - return - a.getX - + b.getX - - c.getX - } - - Expect.equal actual (Some 4) "Should be Some 4" - - - testCase "Happy Path strings" - <| fun () -> - let hello = "Hello " - let world = "world " - let fromfsharp = "from F#" - - let actual = - option { - let! a = hello - and! b = world - and! c = fromfsharp - return a + b + c - } - - Expect.equal actual (Some "Hello world from F#") "Should be Some" - - testCase "Happy Path ResizeArray" - <| fun () -> - let r1 = ResizeArray [ 3 ] - let r2 = ResizeArray [ 2 ] - let r3 = ResizeArray [ 1 ] - - let actual = - option { - let! a = r1 - and! b = r2 - and! c = r3 - a.AddRange b - a.AddRange c - - return Seq.sum a - } - - Expect.equal actual (Some 6) "Should be Some" - - testCase "Happy Path Option.Some/Nullable" - <| fun () -> - let actual = - option { - let! a = Some 3 - and! b = Nullable 2 - and! c = Nullable 1 - return a + b - c - } - - Expect.equal actual (Some 4) "Should be Some 4" - - testCase "Happy Path Option.Some/Nullable/Objects" - <| fun () -> - let actual = - option { - let! a = Some 3 - and! b = Nullable 2 - and! c = CustomClass 1 - - return - a + b - - c.getX - } - - Expect.equal actual (Some 4) "Should be Some 4" - - - testCase "Happy Combo all" - <| fun () -> - let actual = - option { - let! a = Nullable<_> 3 - and! b = Some 2 - and! c = "hello" - and! d = ResizeArray [ 1 ] - and! e = CustomClass 5 - and! f = Uri "https://github.com/" - return sprintf "%d %d %s %d %d %s" a b c (Seq.head d) e.getX (string f) - } - - Expect.equal actual (Some "3 2 hello 1 5 https://github.com/") "Should be Some" - testCase "Fail Path Option.None" - <| fun () -> - let actual = - option { - let! a = Some 3 - and! b = Some 2 - and! c = None - return a + b - c - } - - Expect.equal actual None "Should be None" - - testCase "Fail Path Nullable" - <| fun () -> - let actual = - option { - let! a = Nullable 3 - and! b = Nullable 2 - and! c = Nullable<_>() - return a + b - c - } - - Expect.equal actual (None) "Should be None" - - testCase "Fail Path Objects" - <| fun () -> - let c1 = CustomClass 3 - let c2 = CustomClass 2 - let c3: CustomClass = null - - let actual = - option { - let! a = c1 - and! b = c2 - and! c = c3 - - return - a.getX - + b.getX - - c.getX - } - - Expect.equal actual (None) "Should be None" - - - testCase "Fail Path strings" - <| fun () -> - let c1 = CustomClass 3 - let c2 = CustomClass 2 - let c3: CustomClass = null - - let actual = - option { - let! a = c1 - and! b = c2 - and! c = c3 - - return - a.getX - + b.getX - - c.getX - } - - Expect.equal actual (None) "Should be None" - - testCase "Fail Path Option.Some/Nullable" - <| fun () -> - let actual = - option { - let! a = Nullable<_> 3 - and! b = Some 2 - and! c = Nullable<_>() - return a + b - c - } - - Expect.equal actual None "Should be None" - - testCase "ValueOption.Some" - <| fun () -> - let actual = - option { - let! a = ValueSome 3 - return a - } - - Expect.equal actual (Some 3) "Should be None" - - testCase "ValueOption.None" - <| fun () -> - let actual = - option { - let! a = ValueNone - return a - } - - Expect.equal actual (None) "Should be None" - ] - let ``OptionCE inference checks`` = testList "OptionCE Inference checks" [ testCase "Inference checks" @@ -552,6 +333,5 @@ let ``OptionCE inference checks`` = let allTests = testList "Option CE tests" [ ceTests - ``OptionCE applicative tests`` ``OptionCE inference checks`` ] diff --git a/tests/FsToolkit.ErrorHandling.Tests/ResultCE.fs b/tests/FsToolkit.ErrorHandling.Tests/ResultCE.fs index 9d1c12b9..7b7d4c98 100644 --- a/tests/FsToolkit.ErrorHandling.Tests/ResultCE.fs +++ b/tests/FsToolkit.ErrorHandling.Tests/ResultCE.fs @@ -338,102 +338,6 @@ let ``ResultCE loop Tests`` = Expect.equal actual (Result.Ok data) "Should be ok" ] -let ``ResultCE applicative tests`` = - testList "ResultCE applicative tests" [ - testCase "Happy Path Result" - <| fun () -> - let actual = - result { - let! a = Ok 3 - and! b = Ok 2 - and! c = Ok 1 - return a + b - c - } - - Expect.equal actual (Ok 4) "Should be ok" - - testCase "Happy Path Choice" - <| fun () -> - let actual = - result { - let! a = Choice1Of2 3 - and! b = Choice1Of2 2 - and! c = Choice1Of2 1 - return a + b - c - } - - Expect.equal actual (Ok 4) "Should be ok" - - testCase "Happy Path Result/Choice" - <| fun () -> - let actual = - result { - let! a = Ok 3 - and! b = Choice1Of2 2 - and! c = Choice1Of2 1 - return a + b - c - } - - Expect.equal actual (Ok 4) "Should be ok" - - testCase "Fail Path Result" - <| fun () -> - let expected = Error "TryParse failure" - - let actual = - result { - let! a = Ok 3 - and! b = Ok 2 - and! c = expected - return a + b - c - } - - Expect.equal actual expected "Should be Error" - - testCase "Fail Path Choice" - <| fun () -> - let errorMsg = "TryParse failure" - - let actual = - result { - let! a = Choice1Of2 3 - and! b = Choice1Of2 2 - and! c = Choice2Of2 errorMsg - return a + b - c - } - - Expect.equal actual (Error errorMsg) "Should be Error" - - testCase "Fail Path Result/Choice" - <| fun () -> - let errorMsg = "TryParse failure" - - let actual = - result { - let! a = Choice1Of2 3 - and! b = Ok 2 - and! c = Error errorMsg - return a + b - c - } - - Expect.equal actual (Error errorMsg) "Should be Error" - - testCase "Multiple errors" - <| fun () -> - let errorMsg1 = "TryParse failure" - let errorMsg2 = "IO failure" - - let actual = - result { - let! a = Choice1Of2 3 - and! b = Error errorMsg1 - and! c = Error errorMsg2 - return a + b - c - } - - Expect.equal actual (Error errorMsg1) "Should be Error" - ] - let ``ResultCE inference checks`` = testList "ResultCE Inference checks" [ @@ -455,6 +359,5 @@ let allTests = ``ResultCE try Tests`` ``ResultCE using Tests`` ``ResultCE loop Tests`` - ``ResultCE applicative tests`` ``ResultCE inference checks`` ] diff --git a/tests/FsToolkit.ErrorHandling.Tests/ResultOptionCE.fs b/tests/FsToolkit.ErrorHandling.Tests/ResultOptionCE.fs index 1f05f957..81b3096e 100644 --- a/tests/FsToolkit.ErrorHandling.Tests/ResultOptionCE.fs +++ b/tests/FsToolkit.ErrorHandling.Tests/ResultOptionCE.fs @@ -415,102 +415,6 @@ let ``ResultOptionCE loop Tests`` = Expect.equal actual (Ok(Some data)) "Should be ok some" ] -let ``ResultOptionCE applicative tests`` = - testList "ResultOptionCE applicative tests" [ - testCase "Happy Path Result" - <| fun () -> - let actual = - resultOption { - let! a = Ok(Some 3) - and! b = Ok(Some 2) - and! c = Ok(Some 1) - return a + b - c - } - - Expect.equal actual (Ok(Some 4)) "Should be ok some" - - testCase "Happy Path Choice" - <| fun () -> - let actual = - resultOption { - let! a = Choice1Of2 3 - and! b = Choice1Of2 2 - and! c = Choice1Of2 1 - return a + b - c - } - - Expect.equal actual (Ok(Some 4)) "Should be ok some" - - testCase "Happy Path Result/Choice" - <| fun () -> - let actual = - resultOption { - let! a = Ok 3 - and! b = Choice1Of2 2 - and! c = Choice1Of2 1 - return a + b - c - } - - Expect.equal actual (Ok(Some 4)) "Should be ok some" - - testCase "Fail Path Result" - <| fun () -> - let expected = Error "TryParse failure" - - let actual = - resultOption { - let! a = Ok 3 - and! b = Ok 2 - and! c = expected - return a + b - c - } - - Expect.equal actual expected "Should be Error" - - testCase "Fail Path Choice" - <| fun () -> - let errorMsg = "TryParse failure" - - let actual = - resultOption { - let! a = Choice1Of2 3 - and! b = Choice1Of2 2 - and! c = Choice2Of2 errorMsg - return a + b - c - } - - Expect.equal actual (Error errorMsg) "Should be Error" - - testCase "Fail Path Result/Choice" - <| fun () -> - let errorMsg = "TryParse failure" - - let actual = - resultOption { - let! a = Choice1Of2 3 - and! b = Ok 2 - and! c = Error errorMsg - return a + b - c - } - - Expect.equal actual (Error errorMsg) "Should be Error" - - testCase "Multiple errors" - <| fun () -> - let errorMsg1 = "TryParse failure" - let errorMsg2 = "IO failure" - - let actual = - resultOption { - let! a = Choice1Of2 3 - and! b = Error errorMsg1 - and! c = Error errorMsg2 - return a + b - c - } - - Expect.equal actual (Error errorMsg1) "Should be Error" - ] - let ``ResultOptionCE inference checks`` = testList "ResultOptionCE Inference checks" [ @@ -532,6 +436,5 @@ let allTests = ``ResultOptionCE try Tests`` ``ResultOptionCE using Tests`` ``ResultOptionCE loop Tests`` - ``ResultOptionCE applicative tests`` ``ResultOptionCE inference checks`` ] diff --git a/tests/FsToolkit.ErrorHandling.Tests/ValueOptionCE.fs b/tests/FsToolkit.ErrorHandling.Tests/ValueOptionCE.fs index 4d743214..40ad5056 100644 --- a/tests/FsToolkit.ErrorHandling.Tests/ValueOptionCE.fs +++ b/tests/FsToolkit.ErrorHandling.Tests/ValueOptionCE.fs @@ -325,226 +325,6 @@ type CustomClass(x: int) = member _.getX = x -let ``ValueOptionCE applicative tests`` = - testList "ValueOptionCE applicative tests" [ - testCase "Happy Path ValueOption.ValueSome" - <| fun () -> - let actual = - voption { - let! a = ValueSome 3 - and! b = ValueSome 2 - and! c = ValueSome 1 - return a + b - c - } - - Expect.equal actual (ValueSome 4) "Should be ValueSome 4" - - testCase "Happy Path Nullable" - <| fun () -> - let actual = - voption { - let! a = Nullable<_> 3 - and! b = Nullable<_> 2 - and! c = Nullable<_> 1 - return a + b - c - } - - Expect.equal actual (ValueSome 4) "Should be ValueSome 4" - - testCase "Happy Path null Objects" - <| fun () -> - // let hello = CustomClass - let actual = - voption { - let! a = CustomClass 3 - and! b = CustomClass 2 - and! c = CustomClass 1 - - return - a.getX - + b.getX - - c.getX - } - - Expect.equal actual (ValueSome 4) "Should be ValueSome 4" - - - testCase "Happy Path strings" - <| fun () -> - let hello = "Hello " - let world = "world " - let fromfsharp = "from F#" - - let actual = - voption { - let! a = hello - and! b = world - and! c = fromfsharp - return a + b + c - } - - Expect.equal actual (ValueSome "Hello world from F#") "Should be Some" - - testCase "Happy Path ResizeArray" - <| fun () -> - let r1 = ResizeArray [ 3 ] - let r2 = ResizeArray [ 2 ] - let r3 = ResizeArray [ 1 ] - - let actual = - voption { - let! a = r1 - and! b = r2 - and! c = r3 - a.AddRange b - a.AddRange c - - return Seq.sum a - } - - Expect.equal actual (ValueSome 6) "Should be Some" - - testCase "Happy Path Option.Some/Nullable" - <| fun () -> - let actual = - voption { - let! a = ValueSome 3 - and! b = Nullable 2 - and! c = Nullable 1 - return a + b - c - } - - Expect.equal actual (ValueSome 4) "Should be ValueSome 4" - - testCase "Happy Path Option.Some/Nullable/Objects" - <| fun () -> - let actual = - voption { - let! a = ValueSome 3 - and! b = Nullable 2 - and! c = CustomClass 1 - - return - a + b - - c.getX - } - - Expect.equal actual (ValueSome 4) "Should be ValueSome 4" - - - testCase "Happy Combo all" - <| fun () -> - let actual = - voption { - let! a = Nullable<_> 3 - and! b = ValueSome 2 - and! c = "hello" - and! d = ResizeArray [ 1 ] - and! e = CustomClass 5 - and! f = Uri "https://github.com/" - return sprintf "%d %d %s %d %d %s" a b c (Seq.head d) e.getX (string f) - } - - Expect.equal actual (ValueSome "3 2 hello 1 5 https://github.com/") "Should be Some" - testCase "Fail Path ValueOption.ValueNone" - <| fun () -> - let actual = - voption { - let! a = ValueSome 3 - and! b = ValueSome 2 - and! c = None - return a + b - c - } - - Expect.equal actual ValueNone "Should be None" - - testCase "Fail Path Nullable" - <| fun () -> - let actual = - voption { - let! a = Nullable 3 - and! b = Nullable 2 - and! c = Nullable<_>() - return a + b - c - } - - Expect.equal actual (ValueNone) "Should be None" - - testCase "Fail Path Objects" - <| fun () -> - let c1 = CustomClass 3 - let c2 = CustomClass 2 - let c3: CustomClass = null - - let actual = - voption { - let! a = c1 - and! b = c2 - and! c = c3 - - return - a.getX - + b.getX - - c.getX - } - - Expect.equal actual (ValueNone) "Should be None" - - - testCase "Fail Path strings" - <| fun () -> - let c1 = CustomClass 3 - let c2 = CustomClass 2 - let c3: CustomClass = null - - let actual = - voption { - let! a = c1 - and! b = c2 - and! c = c3 - - return - a.getX - + b.getX - - c.getX - } - - Expect.equal actual (ValueNone) "Should be None" - - testCase "Fail Path ValueOption.ValueSome/Nullable" - <| fun () -> - let actual = - voption { - let! a = Nullable<_> 3 - and! b = ValueSome 2 - and! c = Nullable<_>() - return a + b - c - } - - Expect.equal actual ValueNone "Should be None" - - testCase "ValueOption.ValueSome" - <| fun () -> - let actual = - voption { - let! a = ValueSome 3 - return a - } - - Expect.equal actual (ValueSome 3) "Should be None" - - testCase "ValueOption.ValueNone" - <| fun () -> - let actual = - voption { - let! a = ValueNone - return a - } - - Expect.equal actual (ValueNone) "Should be None" - ] - - let ``ValueOptionCE inference checks`` = testList "ValueOptionCE Inference checks" [ testCase "Inference checks" @@ -560,7 +340,6 @@ let ``ValueOptionCE inference checks`` = let allTests = testList "ValueOption CE tests" [ ceTests - ``ValueOptionCE applicative tests`` ``ValueOptionCE inference checks`` ] #else