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

implicit argument lists #180

Closed
kiritsuku opened this issue Feb 18, 2016 · 5 comments
Closed

implicit argument lists #180

kiritsuku opened this issue Feb 18, 2016 · 5 comments

Comments

@kiritsuku
Copy link
Member

From @fommil on October 25, 2014 11:24

It is fairly standard practice in implicit-heavy libraries to write implicit parameter lists like this

  def canBuildFromFormat[F, E, T]()(implicit
    cbf: CanBuildFrom[F, E, T],
    ef: SexpFormat[E]
  )

but unfortunately I can't set up scalariform to use this trailing-implicit format. Is this something you could support with a new option?

Note that it is possible to do this sort of thing

  def canBuildFromFormat[F, E, T]()(
    implicit
    cbf: CanBuildFrom[F, E, T],
    ef: SexpFormat[E]
  )

Copied from original issue: daniel-trinh#36

@kiritsuku
Copy link
Member Author

From @nairbv on January 1, 2016 1:36

I'm looking for any way to use scalariform without condensing curried function signatures, but the issue isn't just with implicit parameters, it's any kind of currying.
e.g., when I see code like:

def aReallyLongMethodName(thatHasSomeParameters:WithLongTypes)(andThenAnother:ParameterList) = foo

I'd like to be able to write it as:

def aReallyLongMethodName(thatHasSomeParameters:WithLongTypes)
                         (andThenAnother:ParameterList) = foo

But it automatically gets reformatted back to the first one by scalariform. This prevents me from keeping a tight limit on org.scalastyle.file.FileLineLengthChecker in scalaStyle, and I've often seen single lines of code that get excessively long.

From the preview here it looks like characters aren't monospaced, but what I was getting at in my example is I would typically align the open-paren of my curried parameters, implicit or not.

Ideally I think I'd rather just have scalariform not touch any whitespace between a close and then open paren. I hadn't considered your style for writing implicit parameters.

@kiritsuku
Copy link
Member Author

From @nairbv on January 1, 2016 17:39

I think I'll create a separate issue for what I'm describing since the option I'm requesting for curried parameters is a bit different.

@jkinkead
Copy link
Collaborator

I have a patch that formats implicits all with the keyword attached to the first parameter:

def foo()(
  implicit a: TypeA,
  b: TypeB
): Unit = {}

This could be leveraged into the filer's format if desired.

@fommil
Copy link
Contributor

fommil commented Feb 18, 2016

I've seen that style, it might be a useful addition.

@godenji
Copy link
Collaborator

godenji commented Oct 25, 2017

This works out of the box (0.2.4)

def canBuildFromFormat[F, E, T]()(implicit
  cbf: CanBuildFrom[F, E, T],
  ef: SexpFormat[E]
)

While this is not currently possible

def aReallyLongMethodName(thatHasSomeParameters:WithLongTypes)
                         (andThenAnother:ParameterList) = foo

An alternative solution is

def aReallyLongMethodName
  (thatHasSomeParameters:WithLongTypes)
  (andThenAnother:ParameterList) = foo

Basically, stack param groups and let the library handle indentation.

@godenji godenji closed this as completed Oct 25, 2017
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

No branches or pull requests

4 participants