cloud-fan commented on a change in pull request #35657:
URL: https://github.com/apache/spark/pull/35657#discussion_r826691815
##########
File path: core/src/main/scala/org/apache/spark/util/collection/Utils.scala
##########
@@ -36,4 +36,20 @@ private[spark] object Utils {
}
ordering.leastOf(input.asJava, num).iterator.asScala
}
+
+ /**
+ * Only returns `Some` iff ALL elements in `input` are defined. In this
case, it is
+ * equivalent to `Some(input.flatten)`.
+ *
+ * Otherwise, returns `None`.
+ */
+ def sequenceToOption[T](input: Seq[Option[T]]): Option[Seq[T]] = {
+ input.foldLeft(Option(Seq.empty[T])) {
Review comment:
I think a if-else is easier to read here
```
if (input.forall(_.isDefined)) Some(input.map(_.get)) else None
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]