progs/lecture4.scala
changeset 218 22705d22c105
child 222 e52cc402caee
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/lecture4.scala	Tue Nov 27 21:41:59 2018 +0000
@@ -0,0 +1,11 @@
+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)
+  }
+} 
+
+
+