I am trying to use a scala match expression as a switch statement. I do not have my case values stored in an array and want to generate it during runtime.
while (completedTasks < todoTasks) {
// Submit if machine 0 is ready.
if (status(0) == READY)
submit(0, 1)
// Submit if machine 0 is failed.
if (status(0) == FAILED)
submit(0, 1)
}
How can I convert the above piece of code into a match expression. I am trying to replicate a cloud server and run multiple threads to avoid communication overhead. Assumen having 10 machine.
You can use pattern matching on the ADT Structure.
Here is one of the ways how you can do your example:
You can try out this example in a playground here.