FlatmapSafeSeq - laforge49/Asynchronous-Functional-Programming GitHub Wiki
FlatmapSafeSeq[K, V, V1] is a subclass of Sequence[K, V1] and is used to transform the values of another sequence, while dropping null values. The constructor takes two parameters, (1) another sequence actor, seq: Sequence[K, V], and (2) an instance of Safe. FlatmapSafeSeq takes its mailbox from its seq actor, so its interactions with seq are usually synchronous.
Unlike a function, Safe allows access to other actors.
Test code.
class MapSafe extends Safe {
val alphabet = new java.util.HashMap[Int, String]
alphabet.put(8, "Apple")
alphabet.put(22, "Boy")
alphabet.put(5, "Cat")
override def func(target: Actor, msg: AnyRef, rf: Any => Unit)(implicit sender: ActiveActor) {
val kvPair = msg.asInstanceOf[KVPair[Int, Int]]
rf(alphabet.get(kvPair.value))
}
}
val flatmap = new FlatmapSafeSeq(new Range(0, 10), new MapSafe)
Future(flatmap, Loop((key: Int, value: String) => println(key+" "+value)))
Output.
5 Cat
8 Apple