I think you should consider three possibilities — a populated list, an empty list, or an error — and avoid a lot of inelegant testing to figure out which one has occurred.
Therefore use Trywith List:
def getOrdersOfAllCustomers(): Try[List[Order]] = {
Try(funtionReturningListOfOrders())
}
, Success[List[Order]]; , Failure[List[Order]].
- , - , , . , Try , Option. filter, forEach, map .. , , .
, , , . match:
getOrdersOfAllCustomers() match {
case Success(orders) => println(s"Awww...yeah!")
case Failure(ex) => println(s"Stupid Scala")
}
Try, , .