Skip to content

Commit

Permalink
simplify switch case in mapError in Result
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisho committed Jan 15, 2019
1 parent ff3ec71 commit b2f32af
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Source/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,8 @@ extension Result {
/// - Returns: A `Result` instance containing the result of the transform. If this instance is a success, returns
/// the same instance.
public func mapError<T: Error>(_ transform: (Error) -> T) -> Result {
switch self {
case .failure(let error):
return .failure(transform(error))
case .success:
return self
}
guard case .failure(let error) = self else { return self }
return .failure(transform(error))
}

/// Evaluates the specified closure when the `Result` is a failure, passing the unwrapped error as a parameter.
Expand Down

0 comments on commit b2f32af

Please sign in to comment.