Adding Either type to the Standard Library

Basically an Either<A, A> (or similar) type could have the following extension:

// extension<T> Either<T, T> {
extension Either where First == Second {
  var value: First {
    switch self {
    case .first(let value),
         .second(let value):
      return value
    }
  }
}

Of this could be a non-throwing get() method similar to Result.

However I do not advocate for the inclusion of Either into stdlib with this.

2 Likes