Last active
September 1, 2019 15:05
-
-
Save cowlike/53144912970de8f01a7906b076f34b5b to your computer and use it in GitHub Desktop.
Revisions
-
cowlike revised this gist
Sep 1, 2019 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -38,4 +38,14 @@ OptionT.run run3 |> printfn "%A" run3 >>= (fun p -> lift (return (p * 10))) |> OptionT.run |> printfn "%A" |> ignore let run4 = monad { let realInt: Option<Result<int,string>> = Some (result 1) let! x = ResultT realInt return x * 10 } run4 >>= (fun p -> lift (Some (p * 10))) |> ResultT.run |> printfn "%A" |> ignore -
cowlike revised this gist
Aug 31, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -29,13 +29,13 @@ let run2 = monad { } let run3 = monad { let realInt: Result<int option,string> = return (Some 1) let! x = OptionT realInt return x * 10 } OptionT.run run3 |> printfn "%A" run3 >>= (fun p -> lift (return (p * 10))) |> OptionT.run |> printfn "%A" |> ignore -
cowlike revised this gist
Aug 31, 2019 . 1 changed file with 14 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ let doNextAsyncThing (x:System.DateTime) = async { } let f x = 2 * x let run1 = monad { let! x = lift doAsyncThing let! y = OptionT (doNextAsyncThing x) return f y @@ -22,8 +22,20 @@ let doNextResultThing (rand: System.Random): Result<int option,string> = monad { return (if r < 5 then Some r else None) } let run2 = monad { let! x = lift doResultThing let! y = OptionT (doNextResultThing(x)) return f y } let run3 = monad { let realInt: Result<int option,string> = Ok (Some 1) let! x = OptionT realInt return x * 10 } OptionT.run run3 |> printfn "%A" run3 >>= (fun p -> lift (Ok (p * 10))) |> OptionT.run |> printfn "%A" |> ignore -
cowlike revised this gist
Aug 31, 2019 . No changes.There are no files selected for viewing
-
cowlike revised this gist
Aug 31, 2019 . No changes.There are no files selected for viewing
-
cowlike revised this gist
Aug 31, 2019 . No changes.There are no files selected for viewing
-
cowlike created this gist
Aug 31, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ #r "/Users/cowlike/.nuget/packages/fsharpplus/1.1.0-ci00271/lib/netstandard2.0/FSharpPlus.dll" open FSharpPlus open FSharpPlus.Data let doAsyncThing = async {return System.DateTime.Now} let doNextAsyncThing (x:System.DateTime) = async { let m = x.Millisecond return (if m < 500 then Some m else None) } let f x = 2 * x let run' = monad { let! x = lift doAsyncThing let! y = OptionT (doNextAsyncThing x) return f y } let doResultThing: Result<System.Random,string> = Ok <| System.Random() let doNextResultThing (rand: System.Random): Result<int option,string> = monad { let r = rand.Next(10) return (if r < 5 then Some r else None) } let run2' = monad { let! x = lift doResultThing let! y = OptionT (doNextResultThing(x)) return f y }