Created
April 8, 2018 15:41
-
-
Save cowlike/40617b721e06445e0e8ec7dc8d6d4ca3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tests | |
open Xunit | |
open Swensen.Unquote | |
open Monad | |
[<Fact>] | |
let ``Maybe bind on Just`` () = | |
Just 5 >>= (((*) 10) >> return') =! Just 50 | |
[<Fact>] | |
let ``Maybe fmap on Just`` () = | |
((*) 10) <!> Just 5 =! Just 50 | |
[<Fact>] | |
let ``Maybe Ap on Just`` () = | |
let f x y = x * 100 + y * 10 | |
f <!> Just 5 <*> Just 2 =! Just 520 | |
[<Fact>] | |
let ``Maybe comp expr`` () = | |
do' { | |
return! Just "x" | |
} =! Just "x" | |
[<Fact>] | |
let ``Maybe comp expr with zero`` () = | |
do' { | |
let x = 3 | |
let! y = Just 20 | |
if false then return x + y | |
} =! Nothing | |
[<Fact>] | |
let ``Either bind on Right`` () = | |
Right 5 >>= (((*) 10) >> return') =! Right 50 | |
[<Fact>] | |
let ``Either fmap on Right`` () = | |
((*) 10) <!> Right 5 =! Right 50 | |
[<Fact>] | |
let ``Either Ap on Right`` () = | |
let f x y = x * 100 + y * 10 | |
f <!> Right 5 <*> Right 2 =! Right 520 | |
[<Fact>] | |
let ``Either Ap on Left`` () = | |
let f x y = x * 100 + y * 10 | |
f <!> Right 5 <*> Left "oops" =! Left "oops" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment