I have an Iterator based on a repeatedly function calls:
anObject.synchronized {
Iterator.continually {
anObject.wait() // skip this call for the 1st iteration
Try(anObject.foo())
}.dropWhile(_.isFailure).next()
anObject.notifyAll()
}
I would like to make first iteration without calling anObject.wait(). Certainly, I could make something like the following:
anObject.synchronized {
if (Try(anObject.foo()).isFailure) {
Iterator.continually {
anObject.wait()
Try(anObject.foo())
}.dropWhile(_.isFailure).next()
}
anObject.notifyAll()
}
Is there more elegant or standard approach to obtain same purpose (skip function call on first iteration)
PS Similar task arises when it is needed to print a list with delimiters:
scala> List("a", "b", "c").mkString(", ")
res1: String = a, b, c
So, I hope there is some approach for my question too