New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-3638] Make deep flattening of collections possible #46223
Comments
I'm not actually sure what language feature would support this. In Swift, overload resolution is always performed at compile time; the only way to get dynamic dispatch is to use protocols...or to write it yourself, either by using |
Comment by Raphael (JIRA) |
I don't mean to write |
…but you wouldn't know the ultimate element type. That's just not expressible in Swift's type system, and probably never will be. (I don't think it's expressible in Haskell's type system either.) |
Comment by Raphael (JIRA) > I mean to get dynamic dispatch behavior yourself It's been a while, but I remember encountering problems even with manual dynamic checking. You can't check the parameter/associated type at runtime, or can you? > That's just not expressible in Swift's type system, and probably never will be. That's fine. We'd need some form of on-demand dynamic dispatch (e.g. table dispatch at runtime). Static dispatch is fine, but it apparently just can't do some things that, imho, are rather fundamental. |
That's what generialized existentials do. |
Additional Detail from JIRA
md5: 8f2bdef5eb331bcbed53539567b0a791
Issue Description:
It seems nigh if not actually impossible to write a recursive flattening method for `Collection`. By that I mean that `deepFlatten(c: Collection<Collection<...<T>...>>)` should give a plain `Collection<T>` for all nesting depths.
This feels like a task that the type system and compiler should support.
Find some code and a workaround for arrays (for the case of just counting elements) here.
The text was updated successfully, but these errors were encountered: