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

maybe a good solution for using postfixOps #9870

Closed
scabug opened this issue Jul 25, 2016 · 5 comments
Closed

maybe a good solution for using postfixOps #9870

scabug opened this issue Jul 25, 2016 · 5 comments

Comments

@scabug
Copy link

scabug commented Jul 25, 2016

I have an idea about using an method without parameter as an operator. Maybe we can introduce a symbol like .. or a new identifier to show that the method before it need no parameter.

import scala.language.xxx
"Hello" toList .. foreach println

or

import xxx.??
"Hello" toList ?? foreach println

I think this is elegant, isn't it?

@scabug
Copy link
Author

scabug commented Jul 25, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9870?orig=1
Reporter: Franklin Zhang (chigou79)
Affected Versions: 2.12.0-M5

@scabug
Copy link
Author

scabug commented Jul 26, 2016

@soc said:
Hi Franklin,

proposals for language changes should first be discussed on the scala-debate/scala-internals mailing list.
I'm closing this for now, but if you get the go-ahead feel free to reopen.

Thanks!

(My personal opinion is that this hasn't a chance of being accepted as it would add an additional way of doing the same thing. The idea of postfix ops was that one could leave out the dot ... now the proposal is to reintroduce it with two dots instead? How would that retain the original benefit (of "one less dot to write")? How would 2 dots after a method be better than the existing way of adding one dot in front of the method?)

@scabug scabug closed this as completed Jul 26, 2016
@scabug
Copy link
Author

scabug commented Jul 26, 2016

Franklin Zhang (chigou79) said (edited on Jul 26, 2016 12:55:17 PM UTC):
Thank you for telling me this, and sorry for having not described this clearly.
My idea is from manipulating collections from java by JavaConverters(JavaConversions is deprecated):

import scala.collection.JavaConverters._
import java.util.stream.Collectors

def xxx = someJavaStream collect Collectors.toList() asScala

and then, use it as a scala collection, but i can't continue directly because the method asScala can't be used as an infix operator, I should change it to:

def xxx = (someJavaStream collect Collectors.toList() asScala) map ......
or
def xxx = someJavaStream.collect(Collectors.toList()).asScala.map ....
or
def xxx = {
val sList = someJavaStream.collect(Collectors.toList()).asScala
sList map ....
}

this happened just because the method with zero args isn't able to be regarded as an operator, though i acknowledge using too much operators is not a good habit.

@scabug
Copy link
Author

scabug commented Jul 26, 2016

@dwijnand said:
That's a very good example [~chigou79].

Please open a topic about this on one of the mailing lists and link it here, because I would also like to be able to do this - but then I'm demonstrable in the infix-notation camp already.

Here's an example, present in sbt, of a workaround for essentially this issue - to allow for one to continue to use infix notation: https://github.com/sbt/sbt/blob/v0.13.12/ivy/src/main/scala/sbt/ModuleID.scala#L32-L34

@scabug
Copy link
Author

scabug commented Jul 28, 2016

Franklin Zhang (chigou79) said:
Thank you @dale Wijnand ! I had opened a topic in Scala-Internals yesterday. I can't reply to you in time for some problem of internet.

And sorry again to @simon Ochsenreither for giving you a dozen of mails because of my frequently editing my comment. I haven't used JIRA before. This must have bothered you.

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