Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/14332#discussion_r72016327
--- Diff:
examples/src/main/scala/org/apache/spark/examples/ml/DataFrameExample.scala ---
@@ -54,14 +54,13 @@ object DataFrameExample {
}
}
- parser.parse(args, defaultParams).map { params =>
- run(params)
- }.getOrElse {
- sys.exit(1)
+ parser.parse(args, defaultParams) match {
+ case Some(params) => run(params)
+ case _ => sys.exit(1)
}
--- End diff --
I'm reading http://www.scala-lang.org/api/2.11.8/#scala.Option
The only operations where a function operates on an `Option` have no side
effect:
`val upper = name map { _.trim } filter { _.length != 0 } map {
_.toUpperCase }`
Side effects are applied to the result of `getOrElse` only. What are you
reading?
I wonder if the example conflates two things. It's definitely less
idiomatic to accomplish the _transformation_ with `match`. `println(option
match ...)` would be odd. It pushes the `println` inside though which makes it
less clear what about this is unidiomatic. The code snippets don't actually do
the same thing, even.
I think you're suggesting that this implies the former is more idiomatic.
Yes, but it's also not what you're arguing for. It's crucially different in
that we're talking about `Option.map` or `fold` to achieve side effects. The
example specifically doesn't do that. Calling them "essentially equivalent"
hand-waves past the very point.
I understand FP fine; none of this is beyond any of us. I just don't think
your argument holds together. I am not going to change this code based on this.
I'd welcome other opinions though.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]