This pitch is good but too constrained. It needs to apply to anything that is a throwing property wrapper. Neither Optional nor Result have been converted to be so, but they need to be, as that's what they represent.
As it is, what @tera said is necessary:
public extension ThrowingPropertyWrapper {
/// Assign only non-throwing values.
static func =? (self0: inout Self, self1: Self) {
if .success(catching: try self1.wrappedValue) {
self0 = self1
}
}
/// Assign only non-throwing values.
static func =? (wrappedValue: inout WrappedValue, self: Self) {
try? wrappedValue = self.wrappedValue
}
}
But @ramzesenok's proposed syntax is what actually should be used. ?
should consistently mean "or do nothin' " when it comes afterwards. E.g.
var result = Result { "🪕" }
var success = "🎻"
result =? .init { success }
success =? result
should be
@Result var result = "🪕"
var success = "🎻"
result = .init { success }?
success = result?
I can understand that reading, but that's already what =
does without ?
appended. ?
should mean something different.