Choosing the last element of a list
You can use last, which returns the last element or throws a NoSuchElementException, if the list is empty. scala> List(1, 2, 3).last res0: Int = 3 If you do not know if the list is empty or not, you may consider using lastOption, which returns an Option. scala> List().lastOption res1: Option[Nothing] = None scala> List(1, … Read more