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

Support same-line argument binding for lambdas #2099

Closed
plaflamme opened this issue Jul 17, 2020 · 2 comments · Fixed by #2108
Closed

Support same-line argument binding for lambdas #2099

plaflamme opened this issue Jul 17, 2020 · 2 comments · Fixed by #2108

Comments

@plaflamme
Copy link

It's pretty common to bind names in lambdas using .map { case (foo, bar) => ..., unfortunately, if the expression is multi-line, we're forced to indent the whole expression because the pattern match is moved to a new line which also introduces an indent.

Steps

Given code like this:

val xs = List("a", "b")
xs.zipWithIndex.map { case (c, index) =>
  s"$c -> $index"
}

Problem

Scalafmt formats code like this:

xs.zipWithIndex.map {
  case (c, index) =>
    s"$c -> $index"
}

Expectation

I would like the formatted output to not be modified in this case.

Notes

This seems like a pretty common pattern in scala codebases and it'd be great if scalafmt could support this?

@kitbellew
Copy link
Collaborator

duplicates #150.

@plaflamme
Copy link
Author

Sorry about that. I really tried to find a related issue, but I guess I used the wrong keywords.

It was closed as "Won't fix" in 2018 due to the fact that it was probably not worth pursuing with the implementation at the time. Is that still the case today? I know scalafmt went through some refactorings, perhaps this is now more tractable?

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

Successfully merging a pull request may close this issue.

2 participants