Skip to content
laforge49 edited this page Jul 31, 2011 · 2 revisions

To loop through a sequence, send the Loop message to a sequence actor.

case class Loop[K, V](f: (K, V) => Unit)

The sequence actor will call the function in the Loop message for every key/value pair in the sequence and then return a result of null.

There are thread safety issues with passing a function to an actor, if the function references any mutable state of the sending actor, or if the function sends message to an actor.

Example.

val fact = new java.util.ArrayList[Int]
fact.add(0)
fact.add(1)
fact.add(2)
fact.add(6)
fact.add(24)
val factSeq = new ListSeq(fact)
Future(factSeq, Loop((key: Int, value: Int) => println(key+" "+value)))

Output.

0 0
1 1
2 2
3 6
4 24

LoopTest

Tutorial

Clone this wiki locally