Github user squito commented on a diff in the pull request:
https://github.com/apache/spark/pull/11105#discussion_r56409456
--- Diff: core/src/main/scala/org/apache/spark/util/collection/Utils.scala
---
@@ -36,4 +36,21 @@ private[spark] object Utils {
}
ordering.leastOf(input.asJava, num).iterator.asScala
}
+
+ /**
+ * Signal when empty.
+ * Wraps an iterator and calls the provided call back when the iterator
is consumed. If provided
+ * iterator is empty when, calls func right away.
+ */
+ def signalWhenEmpty[T](itr: Iterator[T], func: () => Unit): Iterator[T]
= {
+ if (itr.isEmpty) {
+ func()
+ }
+ itr.map{x =>
+ if (itr.isEmpty) {
+ func()
+ }
+ x
--- End diff --
looks like its something weird w/ `itr.map` -- this seems to work:
```scala
def signalWhenEmpty[T](itr: Iterator[T], func: () => Unit): Iterator[T] =
{
new SignalWhenEmptyIterator(itr, func)
}
private class SignalWhenEmptyIterator[T](sub: Iterator[T], func: () =>
Unit) extends Iterator[T] {
def hasNext: Boolean = {
val r = sub.hasNext
if (!r) {
func()
}
r
}
def next(): T = {
sub.next()
}
}
```
---
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]