progs/lecture4.scala
changeset 218 22705d22c105
child 222 e52cc402caee
equal deleted inserted replaced
217:e689375abcc1 218:22705d22c105
       
     1 def distinctBy[B, C](xs: List[B], f: B => C, acc: List[C] = Nil): List[B] = xs match {
       
     2   case Nil => Nil
       
     3   case (x::xs) => {
       
     4     val res = f(x)
       
     5     if (acc.contains(res)) distinctBy(xs, f, acc)  
       
     6     else x::distinctBy(xs, f, res::acc)
       
     7   }
       
     8 } 
       
     9 
       
    10 
       
    11