All pastes #464767 Raw Edit

Untitled

public text v1 · immutable
#464767 ·published 2007-04-29 18:13 UTC
rendered paste body
package Demo;

object ControlFlow {
    implicit def all[T] (iterable : Iterable[T]) : Iterator[T] = iterable.elements;
    implicit def spawn[T] (funct : T => Unit) : (T => Runnable) = 
        (arg : T) => new Runnable {
            def run : Unit = funct(arg);}

    def forEach[T] (iter : Iterator[T], action : T => Unit) : Unit = 
        while(iter.hasNext) action(iter.next); 

    def concurrentForEach[T] (iter : Iterator[T], action : T => Runnable) : Unit = 
        forEach(iter, (arg : T) => new Thread(action(arg)).start());

    def main(args : Array[String]) = concurrentForEach(args, (arg : String) => Console.println(arg));
}