Skip to content
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

for inout loop #83

Open
oscbyspro opened this issue Apr 19, 2023 · 2 comments
Open

for inout loop #83

oscbyspro opened this issue Apr 19, 2023 · 2 comments
Labels
await can't be done yet brrr such code, much wow

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Apr 19, 2023

There's a pitch related to Swift's ownership model for mutating iterated collection's elements in-place. I do it a lot in this package, so I'm looking forward to it. The gist of it is replacing the first with the second example:

var index = words.startIndex
while index < words.endIndex {
    mutate(&words[index])
    words.formIndex(after: &index)
}
for inout word in words {
    mutate(&word)
}
@oscbyspro oscbyspro added brrr such code, much wow await can't be done yet labels Apr 19, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Apr 19, 2023

That said, I'm also iterating backwards and dunno if that will be supported.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Apr 20, 2023

I suppose this is a closer comparison. I've just gotten used to while loops because they are always fast, whereas I feel like I have to performance profile each instance of .reversed().

for index in words.indices {
    mutate(&words[index])
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
await can't be done yet brrr such code, much wow
Projects
None yet
Development

No branches or pull requests

1 participant