What is the intended usage of the persist method in Akka Persistence for sequences of events? I see that there's a signature like this here:

final def persist[A](events: Seq[A])(handler: (A) ⇒ Unit): Unit

but if I try to call it as in the following example

def receiveCommand= {
  case x ⇒
    val events = Seq(Event("1"), Event("2"))
    persist(events) {
      e ⇒ println(e) // here it gets printed "List(Event(1),Event(2))"

I get printed one single event as List(Event(1),Event(2)). That is, I was expecting to handle each event separately and in the order they are given. But instead, it seems like in the following persist variant

final def persist[A](event: A)(handler: (A) ⇒ Unit): Unit

the type parameter A is replaced by Seq[Event] instead of being replaced by Event and calling the sequence variant. What is the expected way to use this method?


  • Does persist[Event](events) work? – Kolmar Mar 24 '15 at 23:27
  • @Kolmar It doesn't. – ale64bit Mar 25 '15 at 7:54

Be aware that


takes an


as argument so you have to pass in this concrete Seq type:

 val events: scala.collection.immutable.Seq = scala.collection.immutable.Seq("event")   
 persist(events) { event =>
     log.debug("persisted " + event) 
  • So, when you write Seq(1,2,3) without specifying, it is actually a mutable sequence? – ale64bit Mar 25 '15 at 7:52
  • No. In fact it is an immutable sequence as this is the default in scala. But the problem here is that it is not typed as such. You may import scala.concurrent.immutable.Seq on top of your source file to state that all the sequences are immutable. The akka people intended to be sure that the seq must be immutable but should have choosen a different method name to prevent confusion. – Marcus Linke Mar 26 '15 at 8:51

Your Answer

