more canonical list operations;
authorwenzelm
Thu, 24 Apr 2014 10:30:55 +0200
changeset 56688 f3932166a33d
parent 56687 7fb98325722a
child 56689 b8b8b4ff8ad5
more canonical list operations;
src/Pure/System/event_bus.scala
src/Pure/library.scala
--- a/src/Pure/System/event_bus.scala	Thu Apr 24 10:24:44 2014 +0200
+++ b/src/Pure/System/event_bus.scala	Thu Apr 24 10:30:55 2014 +0200
@@ -17,13 +17,13 @@
 
   private val receivers = Synchronized(List.empty[Actor])
 
-  def += (r: Actor) { receivers.change(rs => Library.insert(r, rs)) }
+  def += (r: Actor) { receivers.change(Library.insert(r)) }
 
   def += (f: Event => Unit) {
     this += actor { loop { react { case x => f(x.asInstanceOf[Event]) } } }
   }
 
-  def -= (r: Actor) { receivers.change(rs => Library.remove(r, rs)) }
+  def -= (r: Actor) { receivers.change(Library.remove(r)) }
 
 
   /* event invocation */
--- a/src/Pure/library.scala	Thu Apr 24 10:24:44 2014 +0200
+++ b/src/Pure/library.scala	Thu Apr 24 10:30:55 2014 +0200
@@ -155,10 +155,10 @@
 
   /* canonical list operations */
 
-  def member[A, B](x: B, xs: List[A]): Boolean = xs.exists(_ == x)
-  def insert[A](x: A, xs: List[A]): List[A] = if (member(x, xs)) xs else x :: xs
-  def remove[A, B](x: B, xs: List[A]): List[A] = if (member(x, xs)) xs.filterNot(_ == x) else xs
-  def update[A](x: A, xs: List[A]): List[A] = x :: remove(x, xs)
+  def member[A, B](xs: List[A])(x: B): Boolean = xs.exists(_ == x)
+  def insert[A](x: A)(xs: List[A]): List[A] = if (xs.contains(x)) xs else x :: xs
+  def remove[A, B](x: B)(xs: List[A]): List[A] = if (member(xs)(x)) xs.filterNot(_ == x) else xs
+  def update[A](x: A)(xs: List[A]): List[A] = x :: remove(x)(xs)
 
 
   /* Java futures */