Skip to content
laforge49 edited this page Jul 14, 2011 · 4 revisions

The empty sequence actor is both handy to have and easy to implement. Here's the code.

class EmptySeq
  extends Sequence(null, null) {
  def first(msg: AnyRef, rf: Any => Unit) {
    rf(null)
  }

  def current(msg: AnyRef, rf: Any => Unit) {
    rf(null)
  }

  def next(msg: AnyRef, rf: Any => Unit) {
    rf(null)
  }
}

The empty sequence has no state, so it is an immutable actor which always operates synchronously. It subclasses the Sequence actor, which does the binds for the First, Current and Next messages, as well as supporting the common sequence operations.

Here's the test code.

val emptySeq = new EmptySeq
println(Future(emptySeq, First()))
println(Future(emptySeq, Current(3)))
println(Future(emptySeq, Next("abc")))

And the output.

null
null
null

TestEmpty

Clone this wiki locally