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

Add support for ignoring function arguments #5449

Open
scabug opened this issue Feb 9, 2012 · 5 comments
Open

Add support for ignoring function arguments #5449

scabug opened this issue Feb 9, 2012 · 5 comments

Comments

@scabug
Copy link

scabug commented Feb 9, 2012

When a method of a specific signature needs to be implemented, it would be helpful to somehow mark the arguments that are not going to be used.

Currently, the best solution is that we assign an argument name that hints that it is obviously not going to be used.

def render(dontUseMe: NodeSeq) = {
  ...
}

I propose that we add a yet additional usage of the underscore, this time for ignoring a method argument.

def render(_: NodeSeq) = {
  ...
}

This should fit in nicely with the already existing method of ignoring the argument when creating a function value:

val render = (_: NodeSeq) => {
  ...
}

It is also compatible (in spirit) with the pattern matching system for ignoring everything but the type of the argument.

case _: NodeSeq =>
  ...
@scabug
Copy link
Author

scabug commented Feb 9, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5449?orig=1
Reporter: @melezov
Affected Versions: 2.10.0

@scabug
Copy link
Author

scabug commented Jun 11, 2012

@adriaanm said:
Assigning to community for a more detailed proposal, discussion on scala-internals, etc.

@scabug
Copy link
Author

scabug commented Dec 22, 2014

Shelby Moore III (shelby) said:
Bump. There is more than minor. Self-documenting code is very important. Why should the reader of the code have to go searching through the entire function body to realize the function parameter is not used.

@scabug
Copy link
Author

scabug commented Dec 22, 2014

@melezov said:
I've especially found this to be bothersome when building DSLs which pass in objects, such as:

    object FROM
    
    object SELECT {
      def *(f: FROM.type) = ???
    }

One could try and use the function value, but this will not work if we need polymorphism...

      val * = (_: FROM.type) => ???
      val * = (_: TO.type) => ??? // clash

@scabug
Copy link
Author

scabug commented Dec 22, 2014

@som-snytt said:
Also typelevel/scala#9

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

1 participant