[swift-evolution] [proposal] Either in the Swift Standard Library
Rob Mayoff
mayoff at dqd.com
Tue Jan 26 00:38:51 CST 2016
On Tue, Jan 26, 2016 at 12:13 AM, Craig Cruden via swift-evolution <
swift-evolution at swift.org> wrote:
> I don’t agree that `Result` as a name is any more intuitive than `Either`
> (a disjointed union). The end result of any function is a `resulting`
> value regardless of what type it is.
>
That's true. Outcome might be a better name than Result. Scala calls it Try.
Anyway, Success and Failure have clear, relevant meanings. Left and Right
have no relevant meaning in most uses of Either. The overwhelming majority
of the motivating examples in the proposal use a type named
Result/Success/Failure type, or use Either/Left/Right to mean
Result/Success/Failure (or Result/Failure/Success). The one example I found
(in Madness) where the names Left and Right are meaningful **also**
confusingly uses the Either type as a Result type in the same statements.
For example:
return .Right(.Right(tree), sourcePos)
The outer Right means Success; the inner Right means the right-hand branch
of an alternation operator (I think). So in the one example I could find
(from the proposal) where the names Left and Right are relevant, the code
would be clearer if it also used a separate Result/Success/Failure type.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160126/fa954252/attachment.html>
More information about the swift-evolution
mailing list