fork download
  1. object Main extends App {
  2. val seq = Seq(3, 5, 3, 8)
  3. val secondMaxOpt = (List[Int]() /: seq)(_.:+(_).sortBy(-_).take(2)).lift(1)
  4. println(secondMaxOpt.fold("too few elements")(_.toString))
  5. }
Success #stdin #stdout 0.4s 2181632KB
stdin
Standard input is empty
stdout
5