I'm learning how to use them right now. When I heard about the feature, I thought the following would be a good use case for conversion, but I'm not having any luck so far.
public extension Optional {
/// Exchange four optionals for a single optional tuple.
/// - Returns: `nil` if any tuple element is `nil`.
init<Wrapped0, Wrapped1, Wrapped2, Wrapped3>(_ optionals: (Wrapped0?, Wrapped1?, Wrapped2?, Wrapped3?))
where Wrapped == (Wrapped0, Wrapped1, Wrapped2, Wrapped3) {
switch optionals {
case let (wrapped0?, wrapped1?, wrapped2?, wrapped3?):
self = (wrapped0, wrapped1, wrapped2, wrapped3)
default:
self = nil
}
}
}
If you could tell me the proper syntax to make this compile, I think I could finish up from there?
func ƒ<each Wrapped>(optionals: repeat (each Wrapped)?) {
switch optionals {
case repeat each let wrapped?: return
case repeat each nil: return
}
}
(I've got the signature, other than wanting to called the rest of them Wrapped
and not being able to.)
init<Wrapped0, Wrapped1, each DontKnowWhatToCallThis>(
_ optionals: (Wrapped0?, Wrapped1?, repeat (each DontKnowWhatToCallThis)?)
) where Self.Wrapped == (Wrapped0, Wrapped1, repeat each DontKnowWhatToCallThis) {