Skip to content

Commit

Permalink
Create a first Try function
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Mar 12, 2015
1 parent 12357bc commit 76966b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### 0.0.20 - 12.03.2015
#### 0.0.21 - 12.03.2015
* Improving C# support

#### 0.0.10 - 10.03.2015
Expand Down
11 changes: 10 additions & 1 deletion src/Chessie/ErrorHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,13 @@ type ResultExtensions () =
static member inline SucceededWith(this:Result<'TSuccess, 'TMessage>) : 'TSuccess =
match this with
| Ok(v,msgs) -> v
| Fail(msgs) -> failwithf "Result was an error: %s" (String.Join(Environment.NewLine, msgs |> Seq.map (fun x -> x.ToString())))
| Fail(msgs) -> failwithf "Result was an error: %s" (String.Join(Environment.NewLine, msgs |> Seq.map (fun x -> x.ToString())))


[<Extension>]
/// Executes the given function on a given success or captures the failure
static member inline Try(func: Func<_>) =
try
ok(func.Invoke())
with
| exn -> fail exn

0 comments on commit 76966b4

Please sign in to comment.