Is there a Scala construct for building and returning a list like so?
def getOutput(isValidInput: Boolean): List[Output] =
if (isValidInput) {
yield Output(1) // Pseudo-code... I know yield is not intended for this!
yield Output(2)
}
Instead of...
def getOutput(isValidInput: Boolean): List[Output] =
if (isValidInput)
List(Output(1), Output(2))
else
Nil
In C# the use of 'yield' allows you to return lazy-evaluated collections - is there something similar in Scala?