I wrote a thread about this here:
The pseudo-code imagines what idiom brackets may look like in Swift.
Optionals would work as proposed in this thread:
var id: Int?
var email: String?
User(|id: id, email: email|)
// Optional<User>
Throws could accumulate errors somehow.
func validate(id: Int) throws -> Int {
if id < 1 { throw ValidationError.invalidId }
return id
}
func validate(email: String) throws -> Int {
if email.index(of: "@") == nil { throw ValidationError.invalidEmail }
return email
}
User(|id: try validate(id: id), email: try validate(email: email)|)
// accumulates multiple errors in Result<User, [Error]>,
// or rethrows some accumulated error type
Async/await could optimize for parallelization:
User(|id: await fetchId(), email: await fetchEmail()|)
// dispatches "fetchId" and "fetchEmail" concurrently