To be specific, the new protocol would look something like:
public protocol OptionalProtocol {
associatedtype Some // Or whatever `Optional`'s associated type is
static func some(_ value: Some) -> Self
}
I believe there were some proposals in the past that suggested an OptionalProtocol, but I think those focused too much on expanding the power of Optional unwrapping and thus quickly entered murky waters. In order to support my use case, all we would need is the protocol definition and the associated type. If folks feel positively about this, I can put a formal proposal together.
Note This issue already kind-of works in one direction via ExpressibleByNilLiteral, though that understandably doesn't give you access to the .some type.
If you don't need a protocol conformance or a property, you can sink the conditional where clause onto the individual methods that need the constraint:
extension Optional {
func foo<T>(...) where Wrapped == Resilient<[T]?>.ProjectedValue
}
For some cases, but if I want to define a function directly on Resilient<T?> with some constraints on T, I don't think there currently exists a way to do so (other than conforming Optional to a protocol I define, as in the example).
Update maybe I can specialize dynamicMember... I'll play around and report back
I think the issue is that I'm defining properties in the extension, not functions. Though I was able to do a nasty workaround involving @dynamicMemberLookup. This workaround still requires a new public type (ArrayErrors) but doesn't require me conforming Optional to my own protocol type, which arguably makes it less nasty than what I have now.