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

Comments

Projects
None yet
3 participants
@masters3d
Contributor

masters3d commented Dec 5, 2016

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

This comment has been minimized.

Collaborator

marcelofabri commented Dec 5, 2016

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

This comment has been minimized.

Contributor

masters3d commented Dec 6, 2016

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

@marcelofabri

This comment has been minimized.

Collaborator

marcelofabri commented Dec 6, 2016

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

This comment has been minimized.

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