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) } }