-
Notifications
You must be signed in to change notification settings - Fork 21
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
scala.Option enhancement #661
Comments
Imported From: https://issues.scala-lang.org/browse/SI-661?orig=1
|
@ingoem said: Personally, I think we should be careful not to bloat the API with special purpose methods. Many things can be expressed with map and flatMap already. Since Option is an Iterable, it interacts with other collections. Function val someSet: Set[Option[Int]] = ...
val set = someSet.flatMap(x=>x) This has the benefit that we maintain the collection type, in this case Set. Other methods such as ifNone don't add much. If we are going to add it, we probably need to add ifSome to Option and ifEmpty and ifNotEmtpy to collections. Saving just a few key strokes doesn't justify this. On the other hand, I sometimes also wish I could express things with Options more concisely. I don't see a good way to do it though. |
@dragos said: for (a <- optionA; b <- optionB; c <- optionC) yield f(a, b, c) I wouldn't add |
@tonymorris said:
|
@ingoem said:
I disagree. Bloating an API has not necessarily to do with (interacting) side-effects. Code should be readable. Introducing methods that do the same as can be achieved by other means in already short and equally well readable ways, or introducing methods with cryptic names bloats an API, IMHO. Most methods in java.lang.String add something new and their names are quite meaningful. That's why I think nobody complains. There are already lots of different ways to achieve things in Scala. Sometimes this is good, sometimes, we should just say no, it's enough.
Yes, I also think join should be there for all Iterables. Maybe we should wait for type constraints in Scala, until we may add this method to the Iterable trait (not all the collection objects). (BTW, "... is essential to ...", "all ... have ..." and "... needs ..." don't add much to a discussion most of the time. They don't say anything about the why's.)
What's the point of writing
Just another way to achieve things.
How can they be shown to improve clarity? iif is a cryptic name, Anyways, I think commonly used classes like Option might be exceptions here and the threshold for introducing slightly cryptic but useful methods might be a bit lower than for other classes. Given the recent discussions about Scala's fold operators and so on we should be careful though. |
@ingoem said: |
@odersky said: |
@SethTisue said: |
There are some fundamental functions missing on scala.Option. Please find them in the attached patch.
The text was updated successfully, but these errors were encountered: