4

using scala wart I get:

  def lastWithRecursion(input: Seq[Int]): Try[Int] = input match {
      case head :: Nil => Success(head)
      case _ :: tail => lastWithRecursion(tail)
      case _ => Failure(new NoSuchElementException("No such element")) // how to avoid inferred type containing nothing.
  }

how to avoid inferred type containing nothing?

Johny T Koshy
  • 3,857
  • 2
  • 23
  • 40
Jas
  • 14,493
  • 27
  • 97
  • 148

1 Answers1

6

Try with added generic to Failure:

def lastWithRecursion(input: Seq[Int]): Try[Int] = input match {
    case head :: Nil => Success(head)
    case _ :: tail => lastWithRecursion(tail)
    case _ => Failure[Int](new NoSuchElementException("No such element")) // how to avoid inferred type containing nothing.
}
Reactormonk
  • 21,472
  • 14
  • 74
  • 123