You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
extensionArraywhere Array.Element :Floopable{func floopAll(){
for element in self{
element.floop()}}}
My external library FloopLibrary provides utility functions that return arrays of floopables either as Array<Floopable> or specialized Array<SpecializedFloopable> (where SpecializedFloopable : Floopable).
I would like my extension function to just work on both types, and like this it only works on types that strictly inherit Floopable. I could make the where clause be 'Array.Element == Floopable' and typecast everything to Array<Floopable>, but I think this typecasting boilerplate is not so elegant and the compiler should be smart enough to see that a protocol 'inherits' itself.
So I'd prefer something like:
extensionArraywhere Array.Element <=Floopable{func floopAll(){
for floop in self{
floop.floop()}}}
Is it possible?
Full demo:
protocolFloopable{func floop()}structTypeA:Floopable{func floop(){print("flooping")}}structTypeB:Floopable{func floop(){print("fl00p1ng")}}extensionArraywhere Array.Element :Floopable{func floopAll(){(selfasArray<Floopable>).eqFloopAll()// I do not like this force casting}}extensionArraywhere Array.Element ==Floopable{func eqFloopAll(){
for floop in self{
floop.floop()}}}lethomogenousFloopables:[TypeA]=[TypeA(),TypeA()]letheterogenousFloopables:[Floopable]=[TypeA(),TypeB()]
homogenousFloopables.floopAll()// eqFloopAll() not available
heterogenousFloopables.eqFloopAll()// floopAll() not available(homogenousFloopables as[Floopable]).eqFloopAll()// I do not like this force casting
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: d2264e785671907a61a2b68407a14555
Issue Description:
Consider extension function:
My external library FloopLibrary provides utility functions that return arrays of floopables either as Array<Floopable> or specialized Array<SpecializedFloopable> (where SpecializedFloopable : Floopable).
I would like my extension function to just work on both types, and like this it only works on types that strictly inherit Floopable. I could make the where clause be 'Array.Element == Floopable' and typecast everything to Array<Floopable>, but I think this typecasting boilerplate is not so elegant and the compiler should be smart enough to see that a protocol 'inherits' itself.
So I'd prefer something like:
Is it possible?
Full demo:
The text was updated successfully, but these errors were encountered: