Add value property to Result

This proposal might seem innocuous, but it's actually demonstrative of a lack of standardization of dependency-injected get accessors. Something needs to be done here, but proceed with caution, because you're setting a precedent for a pattern that's going to grow in popularity now that properties are growing up.

"get"?
https://developer.apple.com/documentation/swiftui/binding/init(get:set:)-7ufcp
"catching body"?
https://developer.apple.com/documentation/swift/result/3139399-init
…"value"?

I say the compiler needs to be improved first, to support Result being elevated to property wrapper status. Then the naming will take care of itself.

Here's what we need:

public var wrappedValue: Success {
  get throws { try get() }
  set { self = .success(newValue) }
}

Here's why we can't have that yet:

  1. // Property wrappers currently cannot define an 'async' or 'throws' accessor
  2. 'set' accessor is not allowed on property with 'get' accessor that is 'async' or 'throws'

The get method can be deprecated after get/set accessors are made accessible as closures.

2 Likes