Skip to content

Commit

Permalink
dotnet-websharper#1289 WIP example isOk
Browse files Browse the repository at this point in the history
  • Loading branch information
rb committed Dec 2, 2022
1 parent f0d134d commit 609802d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/stdlib/WebSharper.Main.Proxies/ResultModule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@
FSharp.Core, Culture=neutral, \
PublicKeyToken=b03f5f7f11d50a3a">]
module private WebSharper.ResultModuleProxy

let Bind f r =
match r with
| Ok x -> f x
| Error e -> Error e

let Map f r =
match r with
| Ok x -> Ok (f x)
| Error e -> Error e

let MapError f r =
match r with
| Ok x -> Ok x
| Error e -> Error (f e)
| Error e -> Error (f e)

let isOk r =
match r with
| Ok _ -> true
| _ -> false
7 changes: 7 additions & 0 deletions tests/WebSharper.Tests/Result.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ let Tests =
equal (r2 |> Result.bind (fun x -> Ok())) (Error "e")
}

Test "isOk" {
let r = Ok 3
let r2 = Error "e"
equal (r |> Result.isOk) true
equal (r2 |> Result.isOk) false
}

}

0 comments on commit 609802d

Please sign in to comment.