Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/14332#discussion_r72009839
--- 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 --
Yes, `Option` has `foreach` as well and would be fine if the use case here
were also to "do _X_ if the `Option` exists" but here we also need "... or do
_Y_ if it doesn't". I'm not sure it's that `Unit` is special or not, but that
it signals there is no meaningful result, which highlights the real issue: the
only purpose is the _side effect_. The difference between transforming a return
value with `fold` or whatever and then exiting with it, and using these
constructs to exit, is precisely the difference here. You are arguing that
side-effects are neither here nor there when thinking about this from a
theoretical _functional programming_ perspective? can't agree with that at all!
Transform without side effects? makes total sense for FP idioms. "Transforms"
with no result and only side effects? not so much.
The blog you link makes the point that `fold` is concise, but less
readable, and I agree, and I think that's a negative. The Scala API doc shows
`match` in an example where side-effects are desired (`println`) and not for
transformation. How about `if-else`? I do not particularly think `match` is
necessary.
It's a good discussion but for consistency and readability I think this
change (or to `if-else`) is positive.
---
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]