Skip to content

Commit

Permalink
fix(try): pass error into matcher
Browse files Browse the repository at this point in the history
Pass a Try's error into the Failed case on a match. This emulates more closely the original Scala Try API.

Closes #15.
  • Loading branch information
mrmurphy committed Jul 5, 2017
1 parent 5be912b commit dff5b61
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/try/failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Failure<A> implements Try<A> {
return new Failure<B>(this.error);
}

match<B>(matcher: { Success: (a: A) => B, Failure: () => B }): B {
return matcher.Failure();
match<B>(matcher: { Success: (a: A) => B, Failure: (e: Error) => B }): B {
return matcher.Failure(this.error);
}

orElse<B, A extends B>(this: Failure<A>, alternative: () => Try<B>): Try<B> {
Expand Down
2 changes: 1 addition & 1 deletion src/try/success.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Success<A> implements Try<A> {
return new Success(f(this.value));
}

match<B>(matcher: { Success: (a: A) => B, Failure: () => B }): B {
match<B>(matcher: { Success: (a: A) => B, Failure: (e: Error) => B }): B {
return matcher.Success(this.value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/try/try.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Try<A> {
get(): A;
getOrElse<B, A extends B>(this: Try<A>, defaultValue: () => B): B;
map<B>(f: (value: A) => B): Try<B>;
match<B>(matcher: { Success: (a: A) => B, Failure: () => B }): B;
match<B>(matcher: { Success: (a: A) => B, Failure: (e: Error) => B }): B;
orElse<B, A extends B>(this: Try<A>, alternative: () => Try<B>): Try<B>;
recover(fn: (error: Error) => A): Try<A>;
recoverWith(fn: (error: Error) => Try<A>): Try<A>;
Expand Down

0 comments on commit dff5b61

Please sign in to comment.