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

Prefer function as a parameter instead of simple trailing closure #929

Open
masters3d opened this issue Dec 5, 2016 · 4 comments
Open

Comments

@masters3d
Copy link
Contributor

This is an exception to #54.

If the trailing closure is simple then prefer

result.map(stripTrailingWhitespace)

instead of

result.map { stripTrailingWhitespace($0) }

reference:
exercism/swift#209 (comment)

@marcelofabri
Copy link
Collaborator

I don't think this is directly related to #54, as it would just validate this behavior:

// triggers
result.map({ stripTrailingWhitespace($0) })

// ok
result.map { stripTrailingWhitespace($0) }

@masters3d
Copy link
Contributor Author

"Trailing closure syntax should be used whenever possible."?

@marcelofabri
Copy link
Collaborator

I don't think the description totally matches what it'd be validated. Maybe @jpsim can confirm, but I feel that rule would just validate that if it's a closure and it's the last parameter, trailing syntax should be used. Function references would always be valid for that rule.

@jpsim
Copy link
Collaborator

jpsim commented Dec 7, 2016

@marcelofabri's last comment is spot on 👌. I would like a rule that can recommend using result.map(stripTrailingWhitespace) over result.map { stripTrailingWhitespace($0) } but in practice, that's challenging to build because you need to detect whether or not doing so would be ambiguous (e.g. cannot resolve between function overloads by the same name).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants