Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def maxList[T <% Ordered[T]](elements: List[T]): T =
- elements match {
- case List() =>
- throw new IllegalArgumentException("empty list!")
- case List(x) => x
- case x :: rest =>
- val maxRest = maxList(rest) // (orderer) is implicit
- if (x > maxRest) x // orderer(x) is implicit
- else maxRest
- }
Add Comment
Please, Sign In to add comment