Skip to content
laforge49 edited this page Oct 28, 2011 · 5 revisions

ExcludeSeq wraps 2 other sequences and creates a sequence containing all the key/value pairs of the first sequence, excluding those keys present in the second sequence.

Test code.

val range2 = new Range(1, 10)
range2.setMailbox(new ReactorMailbox)
val seq = new FilterSeq(range2, (x: Int) => x % 2 == 0)
val range3 = new Range(1, 200)
range3.setMailbox(new ReactorMailbox)
val exclude = new FilterSeq(range2, (x: Int) => x % 3 == 0)
val excludeSeq = new ExcludeSeq(seq, exclude)
Future(excludeSeq, Loop((key: Int, value: Int) => println(key+" "+value)))

Output.

2 2
4 4
8 8

ExcludeSeqTest

ExcludeSeq is implemented as a subclass of FilterSafeSeq.

class ExcludeSafe[K, V1](exclude: Sequence[K, V1]) extends Safe {
  override def func(msg: AnyRef, rf: Any => Unit)(implicit sender: ActiveActor) {
    val kvPair = msg.asInstanceOf[KVPair[Int, Int]]
    exclude(ContainsKey(kvPair.key)) {rsp => rf(!rsp.asInstanceOf[Boolean])}
  }
}

class ExcludeSeq[K, V, V1](seq: Sequence[K, V], exclude: Sequence[K, V1])
  extends FilterSafeSeq[K, V](seq, new ExcludeSafe(exclude))

Tutorial

Clone this wiki locally