-
Notifications
You must be signed in to change notification settings - Fork 227
Open
Description
I have a few situations where I need to convert a Result to a common type, and looking at other languages fold
seems to exist.
Essentially, this:
public extension Result {
/// Convert either a success or failure into type `U`
public func fold<U>(success: (Value) throws -> U, failure: (Error) throws -> U) rethrows -> U {
switch self {
case .success(let value): return try success(value)
case .failure(let error): return try failure(error)
}
}
}
Good idea / bad idea?
Metadata
Metadata
Assignees
Labels
No labels