progs/lecture4.scala
author Christian Urban <urbanc@in.tum.de>
Tue, 27 Nov 2018 21:41:59 +0000
changeset 218 22705d22c105
child 222 e52cc402caee
permissions -rw-r--r--
updated

def distinctBy[B, C](xs: List[B], f: B => C, acc: List[C] = Nil): List[B] = xs match {
  case Nil => Nil
  case (x::xs) => {
    val res = f(x)
    if (acc.contains(res)) distinctBy(xs, f, acc)  
    else x::distinctBy(xs, f, res::acc)
  }
}