How to do it...

For this recipe, we need to perform the following steps:

  1. First, let's create the classes for events and commands. Create a file named FriendModel.scala inside the com.packt.chapter6 package with the following content:
        package com.packt.chapter6        case class AddFriend(friend: Friend)        case class RemoveFriend(friend: Friend)        case class Friend(id: String)        sealed trait FriendEvent        case class FriendAdded(friend: Friend) extends FriendEvent        case class FriendRemoved(friend: Friend) extends FriendEvent        case class FriendState(friends: Vector[Friend] =         Vector.empty[Friend]) {          def update(evt: FriendEvent) = evt match {            case FriendAdded(friend) => copy(friends :+ friend)            case FriendRemoved(friend) => copy(friends.filterNot(_ ==  friend)) ...

Get Akka Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.