SE-0465: Standard Library Primitives for Nonescapable Types

We postpone generalizing most of the higher-order functions that make Result convenient to use, as we currently lack the means to reason about lifetime dependencies for such functions. But we are already able to generalize the two functions that do not have complicated lifetime semantics: mapError and flatMapError.

The transform closure of the flatMapError method can return a new Success value:

let f: Result<Int, any Error> = .failure(CancellationError())
let s: Result<Int, any Error> = f.flatMapError { _ in .success(42) }

Therefore flatMapError might have the same issue as flatMap and map.

4 Likes