Guest User

Untitled

a guest
Jul 11th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.32 KB | None | 0 0
  1. def maxList[T <% Ordered[T]](elements: List[T]): T =
  2.   elements match {
  3.     case List() =>
  4.       throw new IllegalArgumentException("empty list!")
  5.     case List(x) => x
  6.     case x :: rest =>
  7.       val maxRest = maxList(rest) // (orderer) is implicit
  8.       if (x > maxRest) x // orderer(x) is implicit
  9.       else maxRest
  10.   }
Add Comment
Please, Sign In to add comment