[swift-evolution] [Review] SE-0024 "Optional Value Setter `??=`"

Guillaume Lessard glessard at tffenterprises.com
Tue Feb 16 13:20:03 CST 2016


For: https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md

> • What is your evaluation of the proposal?

Negative.

The intent is interesting, but the ?? operator is simply not a good candidate for a mutating variant, as its left-hand operand and its result are of different types. The arithmetic operators generalize well to mutating variants, as lhs and result are of the same types.


> • Is the problem being addressed significant enough to warrant a change to Swift?

The proposed ??= operator seems like a counterpart to flatMap for the .None path.
I’ve seen this called `recover` in a number of places:

extension Optional {
  public func recover(@noescape transform: () -> Optional) -> Optional {
    switch self {
    case .Some: return self
    case .None: return transform()
    }
  }
}


> • Does this proposal fit well with the feel and direction of Swift?

No.


> • How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

I looked at all the places I have used the ?? operator, and considered my intent; in every case I wanted to get out of Optionality, not keep it going.

Cheers,
Guillaume Lessard



More information about the swift-evolution mailing list