fork download
  1. object Main extends App {
  2. implicit class OrderedList[T <% Ordered[T]](list: List[T]) {
  3. def sorti = list.zipWithIndex.sorted.map(_._2)
  4. }
  5. def f[T <% Ordered[T]](list: List[T]) = list.sorti.sorti
  6. def g[T <% Ordered[T]](list: List[T]) = println(f(list).mkString("[", ", ", "]"))
  7. g(List(1,100,10,10000,1000))
  8. g(List(3,1,4,1,5,9,2))
  9. g(List(0,1,0,1,0,1,0,1))
  10. g(List("A","C","B","E","D"))
  11. import java.time.Month
  12. g(List(Month.MARCH, Month.JANUARY, Month.APRIL, Month.JANUARY, Month.MAY, Month.SEPTEMBER, Month.FEBRUARY))
  13. }
  14.  
Success #stdin #stdout 0.85s 73168KB
stdin
Standard input is empty
stdout
[0, 2, 1, 4, 3]
[3, 0, 4, 1, 5, 6, 2]
[0, 4, 1, 5, 2, 6, 3, 7]
[0, 2, 1, 4, 3]
[3, 0, 4, 1, 5, 6, 2]